struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Paransky <ap...@standardset.com>
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
example:

instead of:
  property="id"
  property="description"

use:
  property="purposes[1].id"
  property="purposes[1].description"

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"
indexId="count">
      <tr>
        <td valign="top" align="right"
class="formLabel"><%=count.intValue()+1%>:</td>
        <td valign="top" align="left" class="formEntry">
          <html:file size="75" property="<%="files[" + count + "]"%>" /><br>
        </td>
      </tr>
    </logic:iterate>

This should get you started...

-AP_
http://www.myprofiles.com/member/profile/apara_personal

-----Original Message-----
From: Kevin HaleBoyes [mailto:kzboyes@yahoo.com]
Sent: Monday, October 14, 2002 7:54 AM
To: struts-user@jakarta.apache.org
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
relationship).

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">
<table>
<logic:iterate id="p" name="LoansForm" property="purposes">
  <tr><td>
      <html:text name="p" property="id" size="15"/>
  </td><td>
      <bean:write name="p" property="description" filter="true"/>
  </td></tr>
</logic:iterate>
</table>
<html:submit>Save</html:submit>
</html:form>


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.
Thanks,
Kevin.

__________________________________________________
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More
http://faith.yahoo.com

--
To unsubscribe, e-mail:
<mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:struts-user-help@jakarta.apache.org>



--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message