I wish I had another solution to the problem.

I am using ArrayList and it is initialized on IndexedAction (see attached)
=========
for ( int i=0; i<10; i++ ) {
NameValue nv = new NameValue( "" ,new Integer(i) );
al.add( nv );
}
=========

The values show on the page. But when you submit the form, the ArrayList vanish.
Where is the ArrayList size 10 initialize ?

The exception happens on BeanUtils.populate before execute the submit action.

If you can make the code attached work with scope="request" I will be surprised

Please take a look in the code before suggested what is already implemented.

Thank you,
Leo


From: [EMAIL PROTECTED]
Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Subject: RE: Re: struggling with indexed/repeating input fields
Date: Tue, 19 Nov 2002 17:52:52 +0100

HI,
I think u are suggesting that every form has to be in session scope which is
dangerous and will unnecessarily clog the session object.

If u have problems when calling setters on u r form because the list on form is
smaller, i will suggest following approach.

public class MyForm {
private List objectList = new ArrayList();
//use arrayList instead of array as it does not force u to declare size
public Object getObject(index i){
while(index >= this.getList().size() ){
this.getList().add(new Object());
}
return this.getList().getObject(index);
}
}

So in this case, when the setter is called,the form will be added with bean
first nd then the setter will be called.
Try this approach and let me know.

Regards,
Shirish

-----Original Message-----
From: leomaciel [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, November 19, 2002 5:43 PM
To: struts-user
Cc: leomaciel
Subject: Re: struggling with indexed/repeating input fields



I GOT IT!

I forgot to send the struts-config.xml and there were the difference

<VERY-IMPORTANT>
if I set the action scope="request" I get:
javax.servlet.ServletException: BeanUtils.populate
...
Caused by: java.lang.IndexOutOfBoundsException: Index: 2, Size: 0
or
Caused by: java.lang.NullPointerException

make sure you don't have scope="request" in your <action ... </action>
</VERY-IMPORTANT>


======= my struts-config.xml =======
<form-beans>
...
<form-bean name="IndexedForm" type="test.IndexedForm" />
<form-bean name="ParametersForm" type="test.ParametersForm" />
</form-beans>
...
<action path="/indexed"
type="test.IndexedAction"
name="IndexedForm"
validate="false"
>
<forward name="success" path="/indexed.jsp"/>
</action>

<action path="/indexedResult"
type="test.IndexedResultAction"
name="IndexedForm"
validate="false"
>
<forward name="success" path="/indexedResult.jsp"/>
</action>

<action
path="/ShowParameters"
type="test.ShowParametersAction"
name="ParametersForm"
validate="false"
>
<forward name="success" path="/parameters.jsp" />
</action>

<!-- Save parameters -->
<action
path="/SaveParameters"
type="test.SaveParametersAction"
name="ParametersForm"
validate="false"
>
<forward name="success" path="/indextest.jsp" />
</action>
===================================
Try it out.

Cheers,
Leo



>From: "Leonardo Maciel" <[EMAIL PROTECTED]>
>Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: Re: struggling with indexed/repeating input fields
>Date: Tue, 19 Nov 2002 15:33:04 +0000
>
>Kevin,
>
>I finally got
><logic:iterate ... <html:text ... indexed="true"/> ... </logic:iterate>
>to work.
>
>The sample code came from
>http://www.mail-archive.com/struts-user@jakarta.apache.org/msg12084.html
>Thank you Dave.
>
>I built Dave's code on top of struts-example. All necessary code is
>attached.
>On the index.jsp page there are two links
>
><html:link page="/indexed.do">Iterate html:text indexed example</html:link>
>
><html:link page="/ShowParameters.do">From Dave Iterate html:text indexed
>example</html:link>
>
>The first one, indexed.do, doesn't work. Gives IndexOutOfBoundException.
>The second, ShowParameters.do, works. :D
>
>I still trying to figure out the differences between those two...
>
>Good luck!
>Leo
>
>
>
>>From: Kevin HaleBoyes <[EMAIL PROTECTED]>
>>Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
>>To: [EMAIL PROTECTED]
>>Subject: struggling with indexed/repeating input fields
>>Date: Tue, 19 Nov 2002 07:10:15 -0800 (PST)
>>
>>I've asked this question several times on this mailing list but
>>I've never received an answer that would help. I've dug a bit
>>deeper and understand more about the problem but I'm still really
>>struggling with indexed/repeating input fields so I thought I'd
>>ask again. I'm starting to wonder if it is possible.
>>
>>In my ActionForm I have an array property that is initialized to
>>null (I don't know the values until the Action executes).
>>I have a getter
>>that returns the entire array and a setter that takes an array.
>>I also have indexed getters and setters. The array is of another
>>class (that simply has two strings in it with the default/empty
>>constructor and getters and setters).
>>
>>In my (edit) action I construct an array and call the setter in the
>>action form instance (that I just created). I then forward to a JSP
>>page that has a <logic:iterate> tag and <html:text> tags all within
>>a form tag. The form has a <html:submit> that calls my save action.
>>The save action simply forwards to a "confirmation" JSP page that
>>has a similar iteration to display the input values.
>>
>>The initial "edit" form gets displayed properly - the expected
>>number of iterations are performed and the expected values of the
>>input fields is shown. When I press the submit button things break.
>>I know that isn't terribly descriptive but "how" it breaks depends
>>on how I form the <html:text> tags - there are two cases that I've
>>tried.
>>
>>In the first case, I use the following in the "edit" JSP form:
>>
>><logic:iterate id="li" name="IndexedForm" property="lineItem">
>> <html:text name="li" property="itemNo" indexed="true"/>
>> <html:text name="li" property="desc" indexed="true"/>
>></logic:iterate>
>>
>>As I said, it displays properly. I change the "desc" text and hit
>>the submit button and end up getting an exception:
>>
>> ApplicationDispatcher[/cml] Servlet.service() for servlet
>> jsp threw exception
>> org.apache.jasper.JasperException: No collection found
>>
>>In the "save" action I printed the toString() of the input form
>>before forwarding to the JSP page and can see that the array is
>>in fact null. Why is it null? Who is responsible for instantiating
>>an array for that field - struts or the application? If it is the
>>application, how can it know how big to make the array?
>>
>>
>>In the second case, I use the following in the "edit" JSP form:
>>
>><logic:iterate id="li" name="IndexedForm"
>> property="lineItem" indexId="i">
>> <% String prop1 = "lineItem[" + i + "].itemNo"; %>
>> <html:text property="<%= prop1 %>" size="30"/>
>> <% String prop2 = "lineItem[" + i + "].desc"; %>
>> <html:text property="<%= prop2 %>" size="30"/>
>></logic:iterate>
>>
>>Again, it displays properly. I change the "desc" text and hit the
>>submit button and end up getting an exception:
>>
>>StandardWrapperValve[action]: Servlet.service() for
>> servlet action threw exception
>>javax.servlet.ServletException: BeanUtils.populate
>>...
>>Caused by: java.lang.NullPointerException
>> at
>>com.illuminat.cml.IndexedForm.getLineItem(IndexedForm.java:286)
>>
>>
>>This happens even before it calls the "save" action.
>>
>>
>>So, I'm at a loss as to how to handle indexed or repeating fields.
>>I've looked at the code in html-setters.jsp and TestBean from the
>>exercise-taglib in the distribution but that uses fixed size
>>arrays and static initializers. It hasn't been simple to go from
>>that to a variable number of array elements and non-static
>>(from a database) initialization.
>>
>>I've also looked in the archives and
>>on the current mailing list and found nothing. Actually, I've been
>>seeing more questions regarding indexed properties lately
>>(mostly using
>>DynaBeans) but they are generally going un-answered or not coming
>>up with solutions, just more questions. This is not a complaint
>>as I know everyone is very busy but it does mean that I've not found
>>anything in the archives.
>>
>>Help would be most appreciated. Sample code would be even nicer!
>>Is it even possible with Struts (version 1.1b2)?
>>I can furnish code or a better explaination if needed.
>>
>>Kevin
>>
>>
>>
>>
>>__________________________________________________
>>Do you Yahoo!?
>>Yahoo! Web Hosting - Let the expert host your site
>>http://webhosting.yahoo.com
>>
>>--
>>To unsubscribe, e-mail:
>><mailto:[EMAIL PROTECTED]>
>>For additional commands, e-mail:
>><mailto:[EMAIL PROTECTED]>
>
>
>_________________________________________________________________
>STOP MORE SPAM with the new MSN 8 and get 2 months FREE*
>http://join.msn.com/?page=features/junkmail
><< works.zip >>
>--
>To unsubscribe, e-mail:
><mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail:
><mailto:[EMAIL PROTECTED]>


_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?page=features/junkmail


--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>



--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

_________________________________________________________________
STOP MORE SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail

Attachment: works.zip
Description: Zip compressed data

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>


Reply via email to