• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown

Struts Validator Configuration

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 application.properties (should this be located in WEB-INF/)
# -- Custom messages for this application
NameinputForm.email=Email address
# -- Standard Errors --
# -- 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">
<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= "/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"/>
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.
CLUCK LIKE A CHICKEN! Now look at this tiny ad:
a bit of art, as a gift, that will fit in a stocking
    Bookmark Topic Watch Topic
  • New Topic