This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing indexed property with JSTL

 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question is answered by question number 6 in the JavaRanch Struts FAQ.
 
Durgaprasad Guduguntla
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is official, I have a working CRUD Struts-based application.
It uses iterate tags, I will try to implement it with JSTL.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic