File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Set Bean from JSP using Index Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Set Bean from JSP using Index" Watch "Set Bean from JSP using Index" New topic

Set Bean from JSP using Index

RoshaniG Gopal
Ranch Hand

Joined: May 15, 2006
Posts: 180
Hi all,

I am using JDK 1.4, Struts 1.2.9, WAS 6.0, Win XP.
Page1.jsp- Has a link to show the ordering time and other information for the purchased items for a particular user.
Page2.jsp- Opens the jsp and does a <bean:write> from a collection-ArrayList(which has Java Bean Objects). - This Java bean Object has getXXX() and setXXX() for all the information that is displayed on the Page2.jsp.

The problem is that I want to write the "datesubmittedfrom" (using a calender) from the Page2.jsp. It should be an editable field whereas the others are read only. This field should be set in the the bean and not the Action Form for the same JSP)
I am confused, the is populated from the database(after some manipulation). Can i call the setDatesubmittedfrom()directly from the JSP ??
I have used indexed properties and saw a recent post also given by Merrill, but still couldnt reach a solution.
If this is not the right way, can you please guide me through the correct way.
Help would be appreciated.

------------------------ (ActionForm)

public class CalValueForm extends ActionForm
private ResultBean allData=null;
private ArrayList results;

public ResultBean getAllData(int index){
return (ResultBean) this.results.get(index);


public void setAllData(int index, ResultBean resultBean){
---------------- (Java Bean Object)

public class ResultBean
private static StringNOT_A_DATE= "mm/dd/yy";
private Stringdatesubmittedfrom= NOT_A_DATE;
// other getXXX() and setXXX()

public void setDatesubmittedfrom(String datesubmittedfrom) {
this.datesubmittedfrom = datesubmittedfrom;

public String getDatesubmittedfrom() {
return datesubmittedfrom;

<logic:iterate id="result" name="inputForm" property="results" indexId="ctr">

<td><bean:write name="result" property="itemID"/></td>
<td><bean:write name="result" property="typeOfItem"/></td>
<td><bean:write name="result" property="PurchaseDate"/></td>
<html:form action="/addCal" styleId="calValueForm">
<html:text name="calValueForm"
property= '<%= "allData[" + ctr + "].datesubmittedfrom" %>' />


[ October 11, 2006: Message edited by: RoshaniG Gopal ]

[ October 11, 2006: Message edited by: RoshaniG Gopal ]
[ October 11, 2006: Message edited by: RoshaniG Gopal ]

Regards,<br />Roshani
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Everything looks good except for one thing:

The <html:form> tag should not be inside the <logic:iterate> loop. The beginning tag should be right after the <body> tag and the end tag should be right before the </body> tag, so that there is only one form on the page.

If your ActionForm is in session scope, it should work fine. However, if your ActionForm is in request scope, you will also have to add some "lazy initialization" behavior to your indexed getter. This link will explain how to do it.

Consultant, Sima Solutions
RoshaniG Gopal
Ranch Hand

Joined: May 15, 2006
Posts: 180
Hi Merrill,
Thanks for the reply. But i was not able to set the value of setDatesubmittedfrom() in the ResultBean. I tried after removing the <html:form> as you suggested.

I agree. Here's the link:
subject: Set Bean from JSP using Index
It's not a secret anymore!