| Author |
DynaAction and validation
|
Abhay Kumar
Greenhorn
Joined: Jun 03, 2003
Posts: 15
|
|
Hi, I am trying to validate using the Validator frame work and try to avoid the ActionForm. The page is not getting validated Can You Help me out Here is the code: ---------- "Customer.jsp" <%@ page language="java" %> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %> <head> <title>Example of a standard Customer form</title> </head> <h1>Example of a standard Customer form</h1> <body> <html:form action="/addCustomer.do"> Last Name: <html:text property="lastName"/> <html:errors property="lastName" /><br> First Name: <html:text property="firstName"/> <html:errors property="firstName" /><br> Street Addr: <html:text property="street"/> <html:errors property="street" /><br> City: <html:text property="city"/> <html:errors property="city" /><br> State: <html:text property="state" maxlength="2" size="2" /> <html:errors property="state" /><br> Postal Code: <html:text property="postalCode" maxlength="5" size="5" /> <html:errors property="postalCode" /><br> Telephone: <html:text property="phone" maxlength="11" size="11" /> <html:errors property="phone" /><br> <html:submit/> </html:form> </body> ------------------------------------- "config.xml" Plug-in in included <form-beans> <form-bean name="dynaCustomerForm" type="org.apache.struts.validator.DynaValidatorForm"> <form-property name="lastName" type="java.lang.String"/> <form-property name="firstName" type="java.lang.String"/> <form-property name="street" type="java.lang.String" /> <form-property name="city" type="java.lang.String"/> <form-property name="state" type="java.lang.String"/> <form-property name="postalCode" type="java.lang.String"/> <form-property name="phone" type="java.lang.String"/> </form-bean> </form-beans> <action-mappings> <action path="/addCustomer" type="AddCustomerAction" name="dynaCustomerForm" scope="request" input="/Customer.jsp"> <forward name="success" path="/addCustomerSucceeded.jsp" redirect="false" /> </action> </action-mappings> ---------------------------------------- "AddCustomerAction.java" import org.apache.struts.action.*; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionForm; import org.apache.struts.validator.DynaValidatorForm; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.ServletException; import java.io.IOException; public class AddCustomerAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ DynaValidatorForm custForm =(DynaValidatorForm)form; System.out.println("lastName = " + custForm.get("lastName")); System.out.println("firstName = " + custForm.get("firstName")); System.out.println("street = " + custForm.get("street")); System.out.println("city = " + custForm.get("city")); System.out.println("state = " + custForm.get("state")); System.out.println("postalCode = " + custForm.get("postalCode")); System.out.println("phone = " + custForm.get("phone")); return mapping.findForward("success"); } } --------------------------------------- "Validation.xml" <formset> <form name=dynaCustomerForm > <field property="lastName" depends="required" > <arg0 key="dynaCustomerForm.lastName.label" /> </field> <field property="firsttName" depends="required" > <arg0 key="dynaCustomerForm.firstName.label" /> </field> <field property="street" depends="required" > <arg0 key="dynaCustomerForm.street.label" /> </field> <field property="city" depends="required" > <arg0 key=”dynaCustomerForm.city.label”/> </field> <field property=”state” depends=”required,mask”> <arg0 key=”dynaCustomerForm.state.label”/> <var> <var-name>mask</var-name> <var-value>${states}</var-value> </var> </field> <field property=”postalCode” depends=”required,mask”> <arg0 key=”dynaCustomerForm.postalCode.label”/> <var> <var-name>mask</var-name> <var-value>${zip}</var-value> </var> </field> <field property=”phone” depends=”required,mask ”> <arg0 key=”dynaCustomerForm.workPhone.label ”/> <var> <var-name>mask</var-name> <var-value>${phone}</var-value> </var> </field> </form> </formset> -------------------------------------------------
|
 |
Chris Mathews
Ranch Hand
Joined: Jul 18, 2001
Posts: 2712
|
|
Do you have the validator enabled in your struts-config.xml? The configuration looks similar to this:
|
 |
Abhay Kumar
Greenhorn
Joined: Jun 03, 2003
Posts: 15
|
|
yes, I have enabled the plug-in. But even then I am unable to get the result
|
 |
 |
|
|
subject: DynaAction and validation
|
|
|