Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

retrieve beans value using EL expressions

 
Sebastian Green
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Sebastian Green
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, this for ....



Now how do I retrieve myEvangelion from container witch is an Vector?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so to iterate over the Vector (why not an ArrayList?) you would use (again recommending pilot over Pilot):

 
Sebastian Green
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have the JSTL jars in the class path?
 
Sebastian Green
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yepp! And that way its finally works, at last this thread is over thx!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic