This week's book giveaways are in the AI and JavaScript forums.
We're giving away four copies each of GANs in Action and WebAssembly in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

DynaAction and validation

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
-------------------------------------------------
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have the validator enabled in your struts-config.xml? The configuration looks similar to this:
 
Abhay Kumar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, I have enabled the plug-in.
But even then I am unable to get the result
 
My honeysuckle is blooming this year! Now to fertilize this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!