• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using EL to retrieve bean values

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?





 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you using Tomcat 7 and the latest JSP versions?

If not, method calls are not supported by the EL.
 
Graeme Byers
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic