This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Struts Validator Configuration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Validator Configuration" Watch "Struts Validator Configuration" New topic
Author

Struts Validator Configuration

adrian Squires
Greenhorn

Joined: Mar 08, 2004
Posts: 1
Hi,
I am having difficulties configuring the Validator to perform both Server and Client side validation. When trying to submit the jsp I am getting the following exception:
javax.servlet.ServletException: BeanUtils.populate
Root Cause
java.lang.IllegalArgumentException: argument type mismatch
I have done the following:
1. Added the plug in into struts-config.xml:
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />
<set-property property="stopOnFirstError" value="false"/>
</plug-in>
2. Created validator-rules.xml and placed it in WEB-INF/
<form-validation>
<global>
<validator name="required" classname="org.apache.struts.util.StrutsValidator" method="validateRequired" methodParams="java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionErrors, javax.servlet.http.HttpServletRequest" msg="errors.required"/>
<validator name="minlength" classname="org.apache.struts.util.StrutsValidator" method="validateMinLength" methodParams="java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionErrors, javax.servlet.http.HttpServletRequest" depends="required" msg="errors.minlength"/>
</global>
</form-validation>
3. Created validation.xml and placed it in WEB-INF/
<form-validation>
<formset>
<form name="clientSideValidatorForm">
<field property="firstName" depends="required"> <arg0 key="label.firstName.displayame"/> </field>
<field property="lastName" depends="required"> <arg0 key="label.lastName"/> </field> </form>
</formset>
</form-validation>
4. Created application.properties (should this be located in WEB-INF/)
# -- Custom messages for this application
--inputForm.firstName=First
NameinputForm.lastName=Last
NameinputForm.email=Email address
# -- Standard Errors --
errors.header=<FONTCOLOR=RED><UL>
errors.prefix=<LI>
errors.suffix=</LI>
errors.footer=</UL><FONT>
# -- validator --
errors.required={0} is required.
errors.email={0} is an invalid e-mail address.
5. Created jsp page
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<%@ include file="imports.txt" %>
<%@ page import="uk.gov.sunderland.forms.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Validator</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../stylesheets/newstyles.css">
</head>
<body>
<html:javascript formName="clientSideValidatorForm"/>
<html:errors/>
<html:form action= "/clientSideValidatorAction.do" method="POST" onsubmit="return validateclientSideValidatorForm(this);">
Age:<html:text property="age"/>First Name:<html:text property="firstName"/>
Last Name:<html:text property="lastName"/>
e-mail:<html:text property="email"/>Date:<html:text property="date"/>Telephone:<html:text property="telephone"/>
Post Code:<html:text property="postCode"/>
URL:<html:text property="url"/><html:submit property="submit"/></html:form>
<bean:write name="clientSideValidatorForm" property="message"/>
</body>
</html>
6. Created
public class ClientSideValidatorForm extends ValidatorForm and
public class ClientSideValidatorAction extends Action
with appropriate <form-beans>, <global-forwards> and <action-mappings> in struts-config.xml
Am I missing something?
Thanks in advance.
 
 
subject: Struts Validator Configuration
 
Similar Threads
LookupDispatch action with validator
Problem in struts validator
Problem with struts messages
Problem with struts message
struts validation framework error