This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes retrieve beans value using EL expressions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "retrieve beans value using EL expressions" Watch "retrieve beans value using EL expressions" New topic
Author

retrieve beans value using EL expressions

Sebastian Green
Ranch Hand

Joined: Jan 30, 2004
Posts: 136
Im able to retrieve a beans value if its is primitive variabel, String or []String by using EL expression. But what i REALLY want to retrieve is an vector or hashtable, and print out each value of the collection-class. But I cant figure out how to define what kind of value the bean holds (is it called typecast?).

So it would look like this. Bean -> Vector -> Object.
First define Vector from Bean.
Second define Object from Vector.
Third print out optional values from each object.

Is this possible?


/ Sebastian<br />No blog, No homepage, No life?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

Sure it is. You would iterate over the collection using the <c:forEach> tag, and use EL to access each iteration's properties.

Is there a specific example you are having difficulty with?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sebastian Green
Ranch Hand

Joined: Jan 30, 2004
Posts: 136
Yes, this for ....



Now how do I retrieve myEvangelion from container witch is an Vector?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

I'm still not sure what your question is. You have a bean named Pilot -- by the way, you should be using standard Java naming conventions, so the id of the bean should be pilot -- then you create and populate an Evangelion instance and set it as the 'container' property of the bean.

Where's the Vector you speak of? Is the container property an indexed bean property? (If so, should it not be an array?)
Sebastian Green
Ranch Hand

Joined: Jan 30, 2004
Posts: 136
My bad, its supose to be a vector in the bean value not an object, so this is what it would look like

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

OK, so to iterate over the Vector (why not an ArrayList?) you would use (again recommending pilot over Pilot):

Sebastian Green
Ranch Hand

Joined: Jan 30, 2004
Posts: 136
Thanks I will try that one out. To be honest, I really dont now the big diffrent between Arraylist & Vector. All I need is an collection class that can handel objects. And i will change it to pilot . Thanks for the help, you have been most helpful!
Sebastian Green
Ranch Hand

Joined: Jan 30, 2004
Posts: 136
Here is the deal. Im having still having problems to retrieve the value using EL c:forEach. Im able to get the value with this syntax. ${pilots.container[0].name} but when i try to fetch like this


the output is nothing, in the pagesource it says <c:forEach var="entry" items="[uppg4.Evangelion@1d742a1, uppg4.Evangelion@1579371]" >

Here is the jsp-file

And here is the java


As I mention before Im greatfull for help.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

in the pagesource it says <c:forEach var="entry" items="[uppg4.Evangelion@1d742a1, uppg4.Evangelion@1579371]" >


If the <c: tags are being sent to the browser, then you have not properly set up the JSTL taglibs.

Do you have a taglib definition for the 'c' tags in your page?
Sebastian Green
Ranch Hand

Joined: Jan 30, 2004
Posts: 136
Doh! Wonder why my c-scope got printed out as html. I should thought of that... Anyway, I added this line to the jsp-page: <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

and got this error: JSP Parsing Error:Failed to load or instantiate TagLibraryValidator class: org.apache.taglibs.standard.tlv.JstlCoreTLV

I also tried to add the jstl core localy throug defining taglib-uri in the web.xml. But still same error, any ideas?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

Do you have the JSTL jars in the class path?
Sebastian Green
Ranch Hand

Joined: Jan 30, 2004
Posts: 136
yepp! And that way its finally works, at last this thread is over thx!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: retrieve beans value using EL expressions
 
Similar Threads
Best practice to get table form data back to Java beans
problems with &lt;h:selectOneMenu&gt;
Using bean:define
bean in jsp
Size of first Element of a Vector?