struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicolas Lapenne" <nicolas.lape...@naema.org>
Subject Re: parametred name fields
Date Thu, 06 Jun 2002 08:20:43 GMT
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>


Mime
View raw message