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:[EMAIL PROTECTED]]
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:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>



--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
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:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to