Struts: Iterate through array of javabeans

Hi!

I create an array of JavaBeans called "beanProduct" and it is set into session.  Afterwards I want to display the products in a JSP using logic:iterate, but I'm quite new to struts and logic:iterate.  So ... how do I do this?

Before I made a little test with 1 javabean (NOT an array) and then displaying the stuff like this (simplified version):

<jsp:useBean id="beanProduct" scope="session" class="business.BeanProduct" />
...
<table>
  <tr>
    <td><bean:write name="beanProduct" property="pro_name"></td>
  </tr>
  <tr>
    <td><bean:write name="beanProduct" property="pro_description"></td>
  </tr>
  <tr>
    <img src="<html:rewrite page='<%=beanProduct.getProductPicture()%>'/>"  
                                                                             width="150"   height="150">
  </tr>
</table>
...

OK, this works, but now I have an ARRAY of javabeans called "beanProduct".  How do I implement the logic:iterate?  Please notice that, for the image I used beanProduct.getProductPicture(), because apparently you can't nest <bean:write...> there.

Greetings

s5020847


s5020847Asked:
Who is Participating?
 
fargoCommented:
<img src="<bean:write name="beanProduct" property="nameOfImgProperty"/>" >

the above should work.
0
 
fargoCommented:
u can use the following way...
<table>
<logic:iterate id="element" name="beanProduct" scope="session">
  <tr>
    <td><bean:write name="element" property="pro_name"></td>
  </tr>
  <tr>
    <td><bean:write name="element" property="pro_description"></td>
  </tr>
....
</logic:iterate>
</table>

I am not sure about your handling with product picture? Is this picture varies for all the elements in a bean. If it does not vary, you may make it switch in the page with some handler property in a bean with logic tag as below

<logic:equal name="element" property="insertEnabled" value="0">
  <td><img.../></td>
</logic:equal>


0
 
s5020847Author Commented:
Hi!

Ok, that works until here.

The picture varies indeed for every product.  I guess I'll have to change something in:
<jsp:useBean id="beanProduct" scope="session" class="business.BeanProduct" />

Right?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
fargoCommented:
u need not to use useBean now. For image handling, is the property of beanProduct having a path to the image??
0
 
s5020847Author Commented:
Yes indeed.  It contains something like "\pics\productpic01.jsp".  
0
 
s5020847Author Commented:
Oeps, sorry, I mean: "\pics\productpic01.jpg" ... NOT jsp of course.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.