please, try to use JSTL <c:forEach> tag, for example:
regards, Natasza
Philip Tao
Greenhorn
Joined: Feb 08, 2006
Posts: 7
posted
0
Hi Natasza,
I copied the code to my jsp and i get the following error:
org.apache.jasper.JasperException: /Main.jsp(19,0) According to TLD or attribute directive in tag file, attribute items does not accept any expressions
Philip Tao
Greenhorn
Joined: Feb 08, 2006
Posts: 7
posted
0
Hi,
I have gone through the JSTL installation i have and fix the taglib definition in the jsp.
If I leave out the name/id thing and print ${location} I actually get the reference of the object I need (10=org.circe.web.model.Location@9b8ff9/>).I quess you get the same result. So the question is why, if we invoke another method on the bean then toString(), we get the error that the actual object can not be found?
Let me know if you found something, I will do the same
Philip.
Which produces javax.servlet.ServletException: Unable to find a value for "locationId" in object of class "java.util.HashMap$Entry" using operator "."
Philip
Philip Plenckers
Greenhorn
Joined: Jul 25, 2006
Posts: 18
posted
0
Hi Philip,
I guess in this case you have to write your own custom library tag. But as you I'm quite new to this issue.
But from p 438 of HeadFirst Servlets and JSP's I conclude that the <c:forEach> etc. is only capable of invoking the toString() method of the object in the Collection. If this is enough you can simple override this method. Maybe someone else can confirm this?
Philip
Natasza Biecek
Greenhorn
Joined: Oct 26, 2006
Posts: 28
posted
0
Hi Philip & Philip,
Below you have my (working) vision of bean, servlet and jsp, for ArrayList and HashMap both...
CatalogBean.java
catTestServlet.java
and catTestPage.jsp
Originally posted by Philip Plenckers:
MyJSP: <table> <c:forEach var="location" items="${form.locations}"> <tr> <td><cut value="${location.locationId}"/></td> <td><cut value="${location.locationName}"/></td> </tr> </c:forEach> </table> result: javax.servlet.ServletException: Unable to find a value for "locationName" in object of class "java.util.HashMap$Entry" using operator "."
Hmm.... HashMap is a collection of pairs... key + value key identifies an entry, value - contains object... when c:forEach iterates through collection, it extracts these pairs, so, to access fields in your object you have to get the object first via '.value' Please, look at the second part of processRequest() method in code above...
I need a cup of coffee...
regards, Natasza
ps. my current environment is: NetBeans 5.0 (bundled Tomcat 5.5.9), JDK 1.4.2, JSTL 1.1
Philip Plenckers
Greenhorn
Joined: Jul 25, 2006
Posts: 18
posted
0
Hi Natasza,
absolutely great!!!
thanks a lot,
Philip (second)
Philip Tao
Greenhorn
Joined: Feb 08, 2006
Posts: 7
posted
0
Hi Natasza,
Wow! Thanks for the example. It has helped me alot.
At first finding my mistakes was quite hard even though i have your working copy to compare with.
I have discovered the following problems with my code and my setup:
1. I have wrong jstl libraries in the WEB-INF/lib directory. I have a extra library standard-1.0.2.jar and also standard.jar. 2. My java bean class CategoryBean has default access instead of public access (i don't know how i didn't pick it up after checking my code so many times).
I am jumping for joy now too!!
Once again thanks for spending time answering my question.
Regards,
Philip Tao
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: unable to display bean property using ArrayList