Dyna Action and Validator
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Abhay_Kumar
Posted On:   Tuesday, June 10, 2003 11:57 PM

Example of a standard Customer form 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" %> Example of a standard Customer form Last Name: First Name:    More>>
Example of a standard Customer form

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" %>





Example of a standard Customer form







Last Name:



First Name:



Street Addr:



City:



State:



Postal Code:



Telephone:








-------------------------------------
"config.xml"
Plug-in in included





type="org.apache.struts.validator.DynaValidatorForm">













type="AddCustomerAction"
name="dynaCustomerForm"
scope="request"
input="/Customer.jsp">

redirect="false" />


----------------------------------------
"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"





property="lastName"
depends="required" >




property="firsttName"
depends="required" >




property="street"
depends="required" >




property="city"
depends="required" >




property=”state”
depends=”required,mask”>


mask
${states}




property=”postalCode”
depends=”required,mask”>


mask
${zip}




property=”phone”
depends=”required,mask ”>


mask
${phone}




   <<Less
About | Sitemap | Contact