struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Noah Levitt <nlev...@columbia.edu>
Subject Re: parametred name fields
Date Thu, 06 Jun 2002 15:17:33 GMT
Hello,

If I understand your question correctly, it is possible. You
need to use struts 1.1. In your ActionForm, you must have a
field that is a collection of some sort. E.g.

private Vector names;
public Vector getNames() { return names; }
// IIRC you don't you need a setter, could be wrong

The elements of "names" should be beans that have member
functions getName(), setName(String), getSurname(), and
setSurname(String).

Then, in your jsp, do this:

<logic:iterate id="names" name="myActionForm" property="names">
 <tr>
  <td>Surname:</td>
  <td><html:text name="names" property="surname" indexed="true"/></td>
 </tr>
 <tr>
  <td>Name:</td>
  <td><html:text name="names" property="name" indexed="true"/></td>
 </tr>
</logic:iterate>


Be sure to initialize "names" in your ActionForm's constructor
names = new Vector()
or you will get a null pointer exception.

You may also want to fill "names" with one or more empty
name beans so that you have some blank fields on your form
to start out with.

HTH
Noah



On Thu, Jun 06, 2002 at 01:54:07PM +0530, Sai Prasad Baba Subramanyan (Cognizant) wrote:
> I don't think this is possible in Struts.
> 
> -----Original Message-----
> From: Nicolas Lapenne [mailto:nicolas.lapenne@naema.org]
> Sent: Thursday, June 06, 2002 01:51 PM
> To: Struts Users Mailing List
> Subject: Re: parametred name fields
> 
> 
> I know, but by this way I can't use the FormAction objects to fill the form.
> 
> ----- Original Message -----
> From: "Sai Prasad Baba Subramanyan (Cognizant)" <bsai@chn.COGNIZANT.COM>
> To: "Struts Users Mailing List" <struts-user@jakarta.apache.org>
> Sent: Thursday, June 06, 2002 10:03 AM
> Subject: RE: parametred name fields
> 
> 
> Yes, as you can use HttpServletRequest parameter in public ActionErrors
> validate(ActionMapping mapping, HttpServletRequest request) method to do it.
> 
> -Sai
> 
> -----Original Message-----
> From: Nicolas Lapenne [mailto:nicolas.lapenne@naema.org]
> Sent: Thursday, June 06, 2002 01:34 PM
> To: Struts Users Mailing List
> Subject: parametred name fields
> 
> 
> Hello,
> If I have a jsp file with an undeterminated number of components, how can I
> use the ActionForm validation with parametred name fields ? Is it possible
> with struts ? How ?
> 
> example :
> I want the user put the surname and name of n men in a form, and use a
> ActionForm
> without create n instance values.
> 
> *********
> myFile.jsp
> *********
> <%
>  int n = Integer.parseInt( (Integer) request.getAttribute("number"));
> 
>  for(int i=0, i<n, i++){
> %>
>     <tr>
>         <td>Surname :</td>
>         <td>
>             <html:text property="surname<%=i%>" />
>         </td>
>     </tr>
>     <tr>
>         <td>Name :</td>
>         <td>
>             <html:text property="name<%=i%>" />
>         </td>
>     </tr>
> <% } %>
> 
> 
> ******
> MyActionForm.java
> ******
> package myStrutsProject.form;
> import javax.servlet.http.HttpServletRequest;
> import org.apache.struts.action.*;
> import myStrutsProject.commun.*;
> 
> public final class MyActionForm extends ActionForm {
>     private String surname;
>     private String name;
> 
>     // Getters & Setters
>     public String getSurname() {
>         return surname;
>        }
> 
>     public String setName(String name) {
>         this.name = name;
>     }
> 
>     public String getName() {
>         return name;
>        }
> 
>     public String setName(String name) {
>         this.name = name;
>     }
> 
>     public ActionErrors validate(ActionMapping mapping, HttpServletRequest
> request) {
>         ActionErrors errors = new ActionErrors();
>         if (surname = null || name = null) {
>             errors.add("name and surname required", new
> ActionError("error.surnameAndNameRequired"));
>         }
>         return errors;
>      }
> }
> 
> 
> --
> 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>
> 
> 
> 
> ----------------------------------------------------------------------------
> ----
> 
> 
> --
> 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>

> This e-mail and any files transmitted with it are for the sole use of the intended recipient(s)
and may contain confidential and privileged information.
> If you are not the intended recipient, please contact the sender by reply e-mail and
destroy all copies of the original message. 
> Any unauthorised review, use, disclosure, dissemination, forwarding, printing or copying
of this email or any action taken in reliance on this e-mail is strictly 
> prohibited and may be unlawful.
> 
> 		Visit us at http://www.cognizant.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