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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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>


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?
fargoCommented:
u need not to use useBean now. For image handling, is the property of beanProduct having a path to the image??
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

s5020847Author Commented:
Yes indeed.  It contains something like "\pics\productpic01.jsp".  
s5020847Author Commented:
Oeps, sorry, I mean: "\pics\productpic01.jpg" ... NOT jsp of course.
fargoCommented:
<img src="<bean:write name="beanProduct" property="nameOfImgProperty"/>" >

the above should work.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.