This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt 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 Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Validator Configuration" Watch "Struts Validator Configuration" New topic

Struts Validator Configuration

adrian Squires

Joined: Mar 08, 2004
Posts: 1
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"/>
2. Created validator-rules.xml and placed it in WEB-INF/
<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"/>
3. Created validation.xml and placed it in WEB-INF/
<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>
4. Created (should this be located in WEB-INF/)
# -- Custom messages for this application
NameinputForm.lastName=Last address
# -- Standard Errors --
# -- validator --
errors.required={0} is required.{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="*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../stylesheets/newstyles.css">
<html:javascript formName="clientSideValidatorForm"/>
<html:form action= "/" 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"/>
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.
I agree. Here's the link:
subject: Struts Validator Configuration
It's not a secret anymore!