posted 13 years ago
Using EL to retrieve bean values
I don't find it simple.
I don't know whether the required EL syntax is obscure or whether EL does not support the syntax I require.
Surely every servlet/JSP programmer must routinely code office intranet applications like the following ,
(if this is not the case , please let me know) yet the only examples in the books are shopping carts.
How do you do it ? If you use scripting , please let me know.
Thank you for any help.
The business requirement :
Deps have Emps (empNo NUMBER(4) , empName VARCHAR2(10) , hireDate DATE , sal NUMBER(7,2) , depNo NUMBER(2) ).
Code a form to enter a depNo and a View to display all the Emp.empNo and Emp.empName in that Dep.
The coding :
Set up a JavaBean named EmpRowBean populated from each row retrieved from the RDBMS.
Store the result set of all the EmpRowBean's in a List named EmpResultSet.
Store EmpResultSet as an attribute.
In the View , iterate EmpResultSet using <c:forEach> writing out List item each as a <tr>.
No problem - I can do that.
An enhancement to the business requirement :
Change the above View so that you can select a <tr> (add a button to each <tr>) and display all the Emp data for that row on an additional screen View.
The coding :
The value of each button (or hidden field) is set to varStatus in the <c:forEach> so the List item of the selected row is passed as a query parameter which the new View can access <c:set var="rowNo" value="${param.rowNo}" />.
The problem :
Does anyone know the EL syntax that will allow me to retrieve empNo from the attribute , as in ${empList[rowNo].empNo} ?
The coding (a second attempt) :
Re-code the JavaBean : instead of a an attribute that's a List of EmpRowBean , try a JavaBean that contains the result set as a List :
Here is the new additional View :
Which correctly displays :
BEmpView.jsp
rowNo = 1
empList = gbpackage.BEmpResultSetBean@9dca26
empListSize = 3
But if Line X is uncommented then :
I don't know what this message means ?