struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Paransky <>
Subject RE: repeating input fields
Date Mon, 14 Oct 2002 15:12:33 GMT
What you are doing is fine for layout, however, when you hit save how is
struts supposed to know that id is supposed to map to
LoanForm.purposes[??].id, or that descriptions maps to
LoanForm.purposes[??].description.  It does not, so nothing is set in to
your array.  You must emit your properties with all the information that
struts can use to put them back into the form when it's submitted.  For

instead of:


How you put the index into the property does not matter.  You can use the
indexed attribute on some fields and use the index that can be gathered from
the iterator tag.

For example, here is a form that has an array of files:

    <logic:iterate id="file" name="multiPictureCreateForm" property="files"
        <td valign="top" align="right"
        <td valign="top" align="left" class="formEntry">
          <html:file size="75" property="<%="files[" + count + "]"%>" /><br>

This should get you started...


-----Original Message-----
From: Kevin HaleBoyes []
Sent: Monday, October 14, 2002 7:54 AM
Subject: repeating input fields

I know this has been asked before but I'm unable to find anything
in the archive - probably not using the right search terms...

I'm trying to create a form that allows the user to input a list
of strings.  Kind of like a detail block (of a master-detail

So I have

  public class LoanPurpose {
    private String id;
    private String description;
    public String getId() {return id;}
    public void   setId( String v ) { id = v; }
    public String getDescription() {return description;}
    public void   setDescription( String v ) {description = v;}

and a Form bean

  public class LoansForm extends ActionForm {
    private LoansPurpose[] purposes = null;
    public LoanPurpose[] getPurposes() {return purposes;}
    public void setPurposes( LoanPurpose[] v ) {purposes = v;}
    public void reset(ActionMapping mapping,
               HttpServletRequest request) {purposes = null;}

In my JSP form I have:

<html:form action="/saveLoanPurps" method="post">
<logic:iterate id="p" name="LoansForm" property="purposes">
      <html:text name="p" property="id" size="15"/>
      <bean:write name="p" property="description" filter="true"/>

If I stuff a few values into the purposes array in the "edit"
action they properly get displayed when the form is rendered.

This is where I get lost though.  When I hit the "Save" submit
button I don't get the results I expect.  In the Save action I
print the contents of the LoansForm.purposes array and it is null,
instead of having the contents of the input fields.

What am I missing?

Any help would be most appreciated.

Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message