aspose file tools*
The moose likes JSP and the fly likes Using EL to retrieve bean values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Using EL to retrieve bean values " Watch "Using EL to retrieve bean values " New topic
Author

Using EL to retrieve bean values

Graeme Byers
Ranch Hand

Joined: Apr 16, 2004
Posts: 127
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 ?





Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61592
    
  67

Are you using Tomcat 7 and the latest JSP versions?

If not, method calls are not supported by the EL.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Graeme Byers
Ranch Hand

Joined: Apr 16, 2004
Posts: 127
1. I'm using Apache-Tomcat.8.0.16.

2. "Method calls not supported" , well this works :


3. The point I'm concerned to make is that this is standard business app , yet I cannot find a way to code it using EL.
What do servlet/JSP programmers do when asked to code this stuff in their day job ?
I am not getting a reply.

Graeme.
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
Allow me to clarify Bear's statement.

In earlier versions of JSTL method calls other than getter/setter calls are not supported.
That has changed in the last version of JSP, but I'm not completely up to speed with the details.

However, you don't need to use method calls to get what you want with EL in this example.
EL allows you to access the size of a list, and its individual elements.



cheers,
evnafets
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using EL to retrieve bean values