Matt,
Is your form-bean defined like this?

<form-bean name="advancedTaxRatesCurrentForm"
type="org.apache.struts.action.DynaActionForm">
    <form-property name="taxRates" type="com.ntso.rsg.bus.tax.TaxRateBean[]"
/>
</form-bean>

You wrote:
>Also, how would the data get from allTaxRates into the taxRates array in
the form? How does it know that 
>taxRates is an indexed property as opposed to a simple 
>property? Why setup a new TaxRateBean array (taxRates) when 
>allTaxRates is already that?

My assumption was that your form would have a subset of the items in
allTaxRates. If allTaxRates contains all of the TaxRateBeans you want in
your form then you don't need the loop at all.
Since you've defined a form property called "taxRates" in your DynaForm, you
can set the value of that property in your action in order to prepopulate
the form with this:

DynaActionForm taxRatesForm = new DynaActionForm();
taxRatesForm.set("taxRates", allTaxRates);

session.setAttribute("advancedTaxRatesCurrentForm", taxRatesForm);

In your JSP then, I think this code should work w/o producing an
ArrayIndexOutOfBoundsException

<html:form action="admin/taxRatesUpdateAction">
    <logic:iterate id="taxRate" name="advancedTaxRatesCurrentForm"
property="taxRates" indexId="ctr" >
        <html:checkbox indexed="true" name="taxRate" property="delete" />
        <html:hidden indexed="true" name="taxRate" property="ID" />
        <html:text indexed="true" name="taxRate" property="ratePercent"
style="width: 50px; text-align: right;"/>
    </logic:iterate>
    <html:submit value="Update"/>
</html:form>


-Richard





-----Original Message-----
From: Matt Bathje [mailto:[EMAIL PROTECTED] 
Sent: Thursday, November 20, 2003 2:51 PM
To: Struts Users Mailing List
Subject: Re: dynamically sized form


<snip>
 
> DynaActionForm taxRatesForm = new DynaActionForm(); 
> com.ntso.rsg.bus.tax.TaxRateBean[] taxRates = new 
> com.ntso.rsg.bus.tax.TaxRateBean[allTaxRates.length];
> 
> // allTaxRates is the array that holds my data bean
> 
> for(int i=0; i < allTaxRates.length; i++) {
>     // this is the set I am using, from the Struts API:
>     //set(java.lang.String name, int index, java.lang.Object value)
>     //          Set the value of an indexed property with the specified
> name.
>     taxRatesForm.set("taxRates", taxRates);
> }
<snip>

Richard - I tried this, but didn't have much hope, as it doesn't really make
sense to me. What would be the point of doing the set inside a loop over
allTaxRates? Also, how would the data get from allTaxRates into the taxRates
array in the form? How does it know that taxRates is an indexed property as
opposed to a simple 
property? Why setup a new TaxRateBean array (taxRates) when 
allTaxRates is already that?

Anyways, trying your method outright produces a null pointer 
exception.

I tried modifying it to do this in the loop (using allTaxRates so that it
gets the current data): taxRatesForm.set("taxRates", i, allTaxRates[i]); and
it produces an error of:
java.lang.NullPointerException: No indexed value for 'taxRates[0]'

I then tried this, outside of the loop (again using allTaxRates because it
will get the current data) taxRatesForm.set("taxRates", allTaxRates); it
also gives a null pointer exception


Using the set(string, object) method of DynaActionForm doesn't really make
sense to me, so if that is the solution could you explain why? (See all my
questions above about that) Unless I am 
completely braindead (which we can't rule out of course) I think the
set(string, int, object) method needs to be used for this.

Thanks again,

Matt Bathje

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

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

Reply via email to