?
Solved

Struts: Iterate through array of javabeans

Posted on 2006-04-13
6
Medium Priority
?
692 Views
Last Modified: 2006-11-18
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


0
Comment
Question by:s5020847
  • 3
  • 3
6 Comments
 
LVL 11

Expert Comment

by:fargo
ID: 16447687
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
 

Author Comment

by:s5020847
ID: 16447969
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
 
LVL 11

Expert Comment

by:fargo
ID: 16448349
u need not to use useBean now. For image handling, is the property of beanProduct having a path to the image??
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:s5020847
ID: 16448353
Yes indeed.  It contains something like "\pics\productpic01.jsp".  
0
 

Author Comment

by:s5020847
ID: 16448364
Oeps, sorry, I mean: "\pics\productpic01.jpg" ... NOT jsp of course.
0
 
LVL 11

Accepted Solution

by:
fargo earned 1000 total points
ID: 16451832
<img src="<bean:write name="beanProduct" property="nameOfImgProperty"/>" >

the above should work.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
In the below post we have mentioned the best hosting type for startups. Also, check out some of the superlative web hosting companies that are proposing affordable web hosting solutions to host your startup website.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month15 days, left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question