This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes JSF and the fly likes EL with List of Objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "EL with List of Objects" Watch "EL with List of Objects" New topic
Author

EL with List of Objects

Matt Holloway
Ranch Hand

Joined: Oct 16, 2003
Posts: 53
I'm using Hibernate to insert/select data from a database. I have a JavaBean class 'Product' that has the getters/setters that Hibernate uses to insert and get data with. My problem is, when I get the data back from Hibernate, I create a list to store the records in, then pass that list back to the JSP as an attribute. I can iterate through the list using scripting in my JSP, but I'm trying to maintain scriptless JSPs, so I would prefer to use EL and Standard Actions. Is there a way (short of creating a custom taglib) to convert the following to a scriptless JSP?


Here is my (lame) attempt with EL:



I'm attempting to run the getProdName method to return the prodName...
[ November 06, 2005: Message edited by: Bear Bibeault ]
Matt Holloway
Ranch Hand

Joined: Oct 16, 2003
Posts: 53
P.S. I've also tried doing a #{product.prodName} with the same result (i.e. no data returns)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60041
    
  65

The syntax ${product.prodName} is correct for the EL with the JSTL.

Are you getting any iterations? or is the body of the forEach never executing.
[ November 06, 2005: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Matt Holloway
Ranch Hand

Joined: Oct 16, 2003
Posts: 53
I tried with the $ as well, it is not outputting anything. I don't get any errors in the log.

I inserted 'test' into the <td> element in the forEach loop, and it iterated through the correct number of times for the list, but does not put out any of the data from the object in the list.
[ November 06, 2005: Message edited by: Matt Holloway ]
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
That <h:inputText> looks like a Java Server Faces tag.
JSF would be where you got the #{expr} syntax from.
It uses an EL based on the JSTL EL, but uses # instead of $.

Unfortunately I don't think the JSF tags and JSTL tags play together so well. The next version of JSP should rectify that.

Here is the example with pure JSTL


With JSF, you want something like this:

Cheers,
evnafets

(damn I hate those #$%!?! smilies)

[ November 06, 2005: Message edited by: Stefan Evans ]
[ November 06, 2005: Message edited by: Stefan Evans ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60041
    
  65

Something like the use of JSF is something that should be mentioned right off the bat. We have a forum devoted to JSF so I'm going to clean up this topic is bit and move it over to there.
Matt Holloway
Ranch Hand

Joined: Oct 16, 2003
Posts: 53
Thanks. I tried, and both examples you gave worked. It seems as though I was mixing stuff up... I was going from the JSTL spec from the Sun website that I downloaded, and I'm pretty new at JSTL, and about to embark on learning JSF, so that didn't help my case. I'm making an effort to put together scriptless JSPs so that the person who maintains them doesn't come to my house and kill me for using scripts that they don't understand.

I think the key thing I was missing was the <c ut>.

Thanks for the help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EL with List of Objects
 
Similar Threads
question regarding el
Problem iterating rows of a ResultSet with JSP
bean and for each
First/Previous/Next/Last Page
Iterating <c:foreach> to get values from sublist