• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Accessing complex beans in struts

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a problem accessing beans in struts.
My bean looks something like this.
class Category {
private int catId;
private List products;
..
.
}
The list is used to store Product objects.
How can access the products in a jsp page by only
using struts tags?
Using iterate and bean:write will not do the trick because I need to access the objects in the list.
Any ideas?
Thanks.
jay
------
SCJP, SCJD
 
Sheriff
Posts: 17734
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(Edit: sorry about previous edition of this post. I got a couple of things mixed up -- indexed properties are a different thing. You just need a List)
logic:iterate and bean:write should work.

[ December 27, 2002: Message edited by: Junilu Lacar ]
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can create a form bean that has the attributes of
your Category, or some such approach to make the products list
available to the tag library in some scope. The example below
assumes the form bean contains a getProducts() method that returns
your list of products and that the Product object has a
getProductName() method:

<ul>
<logic:iterate id="product" name="yourForm" property="products">
<bean:write name="product" property="productName"/>
</logic:iterate>
</ul>

If the Product object is more complex you can use "dot" syntax
to obtain "deeper" properties. For example, property="type.name"
instructs struts to call getType().getName() on the object.
Hope that helps.
Matthew Marquand
Object Ovation, Inc.
 
jay denzel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,
thanks for your answers.
I just solved the problem myself.
Greets,
jay
-------
SCJP, SCJD
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic