Ciaran Hanley a écrit :
Can somebody help me or propose a solution to the following please.

I wish to create a form dynamically. Depending on the business logic there
could be 0 to N rows in the form. I tried to use a form with an array of
strings and use the indexed="true" setting in the html:text boxes but as I
was not following any example I ran into problems and didn't have any guide
as to where I was going wrong.

I also need to iterate over a bean containing information which corresponds
to the form as the form boxes are being displayed.

Say if there is 3 rows required, it should ok like the following.

Payment     Old Amnt    New Amnt          Date

1           35          [45]              [12/12/04]

2           35          [45]              [12/01/05]

3           35          [45]              [12/02/05]

Where [] represents a html:text box.

I am also unsure as to how to access these values when I get to the
form/action classes.

Any help would be much appreciated!

There are a few ways to do that. The most obvious (according to me) would be to have a "Billing" (for instance) class, with all the attributes that suit you, then :

- use a lazy list (go to http://wiki.apache.org/struts/StrutsCatalogLazyList for more information about them) to store them. The use of LazyList instead of "classical" List (with ArrayList) is all about indexes : when you start from the server and you display the items stored in your list, all is fine.

(something like :

<!-- titles/headers go here -->
<logic:iterate id="item" name="myList">
        <html:text name="formList" property="payment" indexed="true"/>
        <html:text name="formList" property="oldAmnt" indexed="true"/>
        <html:text name="formList" property="newAmnt" indexed="true"/>
        <html:text name="formList" property="date"    indexed="true"/>
        <br/>
</logic:iterate>
)

But when the user clicks on the submit button, a horrible thing happens : IndexOutOfBoundException (because a new List is instanciated from the server side - the old one has been lost as it is a new request - and currently, something like formList.get(0) returns null, which isn't what Struts expected). So you have to make some mechanism to return an object (preferably of the right kind) so Struts remains happy. Hence the LazyLists.

--
Stéphane Zuckerman

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

Reply via email to