I'm having trouble populating a Form bean that has an indexed (variable
size) nested bean.  I'm using an ArrayList inside the Form bean to collect
the nested properties and it's partially working.  The problem is that
because the index is variable, I don't know how to correctly size the
ArrayList.  As a result, the nested beans are being accessed by their index
inconsistently.    I'm trying to dynamically grow it as getBean(int idx) is
called, but it's messy.  Does anyone have a good solution for this?  Thanks
in advance.

JSP:

<c:forEach var='borrowerLiability'
items='${LiabilityForm.borrowerLiability}' varStatus='idx'>
            <tr>
                <html:hidden indexed='true' name='borrowerLiability'
property='liabilityId' />
                <td class="input">
                    <input type="checkbox" name="omit"/>
                </td>
                <td class="input">
                    <html:select indexed='true' name='borrowerLiability'
property='borrowerId'>
                        <html-el:optionsCollection name='property'
property='borrowers' label='canonicalName' value='id' />
                    </html:select>
                </td>
                <td class="input">
                    <html:select indexed='true' name='borrowerLiability'
property='liabilityTypeId'>
                        <html:options
collection='<%=ContextKey.LIABILITY_TYPES%>' property='id'
labelProperty='name' /></option>
                    </html:select>
                </td>
                <td class="input"><html:text indexed='true'
name='borrowerLiability' property='payment' size='7' /></td>
                <td class="input">
                    <html:select indexed='true' name='borrowerLiability'
property='timeIntervalId'>
                        <html:options
collection='<%=ContextKey.TIME_INTERVAL_TYPES%>' property='id'
labelProperty='name' />
                    </html:select>
                </td>
                <td class="input"><html:text indexed='true'
name='borrowerLiability' property='balance' size='7' /></td>
            </tr>
        </c:forEach>

Bean fragment:

public class LiabilityForm extends ValidatorForm implements MonthlyDebts,
DispatchForm {

    private ArrayList borrowerLiability = new ArrayList();
    ... more properties...

    public BorrowerLiability[] getBorrowerLiability() {
        return (BorrowerLiability[]) this.borrowerLiability.toArray(new
BorrowerLiability[0]);
    }
    public BorrowerLiabilityImpl getBorrowerLiability(int idx) {
        BorrowerLiabilityImpl bl;
        if (borrowerLiability.size() <= idx) {
            borrowerLiability.ensureCapacity(idx+1);
            bl = new BorrowerLiabilityImpl();
            borrowerLiability.add(bl);
        } else
            bl = (BorrowerLiabilityImpl) borrowerLiability.get(idx);
        return bl;
    }
    ...more method ...
}


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

Reply via email to