| Author |
Accessing indexed property with JSTL
|
Hussein Baghdadi
clojure forum advocate
Bartender
Joined: Nov 08, 2003
Posts: 3359
|
|
Hi. I'm trying to implement a simple CRUD application. /action/loadCart.do is responsible for populating an action form from shopping cart session-based object. The previous action form has an array consisting of shopping cart's items. And the questions is : How to access this array in cart.jsp page using JSTL ? (just a little snippet if possible)
|
 |
Chris Boldon
Ranch Hand
Joined: Aug 10, 2006
Posts: 190
|
|
|
Instead of using an Array I would use a Collection of objects. Then you would set the Collection to a request in the Action. Then you could access it using JSTL by ${}.
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
|
This question is answered by question number 6 in the JavaRanch Struts FAQ.
|
Merrill
Consultant, Sima Solutions
|
 |
Durgaprasad Guduguntla
Ranch Hand
Joined: Oct 20, 2003
Posts: 99
|
|
Originally posted by John Todd: And the questions is : How to access this array in cart.jsp page using JSTL ? (just a little snippet if possible)
You can use JSTL c:forEach tag to iterate over array as well. Take a look at the following code snippet which will be useful in your object model:
|
Thanks,<br />Durgaprasad<br />SCJP1.4, SCWCD1.4, SCBCD1.3,<br />SCEA
|
 |
Hussein Baghdadi
clojure forum advocate
Bartender
Joined: Nov 08, 2003
Posts: 3359
|
|
Ok, here is more info : cart.jsp should display some thing like : While the tutotial in : http://faq.javaranch.com/view?IndexedProperties is so good, it uses Strut's logic, I want to use JSTL instead. (Well, I will implement it with AJAX later since it makes more sense in this case, but I want to learn how to make it with Struts). Any ideas ? BTW, what do IndexedProperties and StrutsFaq mean in : http://faq.javaranch.com/view?StrutsFaq http://faq.javaranch.com/view?IndexedProperties I understand ? as the begining of the query string, followed by parameters names and values.
|
 |
Hussein Baghdadi
clojure forum advocate
Bartender
Joined: Nov 08, 2003
Posts: 3359
|
|
Ok, I'm trying some thing like : But I got the following exception : javax.servlet.ServletException: No getter method for property: "bookItem" of bean: "cartItem" Well, believe me, there is a getter method !
|
 |
Carol Enderlin
drifter
Ranch Hand
Joined: Oct 10, 2000
Posts: 1348
|
|
You gave up on using jstl tags? Did you try the suggested c:foreach? p.s. are you already set up with jstl or just getting started? The JspFaq has great info about compatible versions, URLs to find the specs (a must have for jstl, very readable). [ November 30, 2006: Message edited by: Carol Enderlin ]
|
 |
Hussein Baghdadi
clojure forum advocate
Bartender
Joined: Nov 08, 2003
Posts: 3359
|
|
Actually, I wrote some thing like : But got I blank page. (Please note, /action/loadCart.do doesn't put any thing in the request scope, I'm trying to access the cart form since it declared to be in the request scope in struts-config.xml)
|
 |
Brent Sterling
Ranch Hand
Joined: Feb 08, 2006
Posts: 948
|
|
In your class CartItem you have a method named (with the exact capitalization) getBookItem()? In your first post you have the property named just "item". Make sure you method is not named getItem(). - Brent
|
 |
Hussein Baghdadi
clojure forum advocate
Bartender
Joined: Nov 08, 2003
Posts: 3359
|
|
Now, I appreciate Generics, I was adding BookItems to the cart form instead of CartItems Delete functionality is working like a devil, but not the update. Aaaa, I hate CRUD with Struts
|
 |
Hussein Baghdadi
clojure forum advocate
Bartender
Joined: Nov 08, 2003
Posts: 3359
|
|
It is official, I have a working CRUD Struts-based application. It uses iterate tags, I will try to implement it with JSTL.
|
 |
 |
|
|
subject: Accessing indexed property with JSTL
|
|
|