• 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 ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Struts Validator Configuration

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
And tomorrow is the circus! We can go to the circus! I love the circus! We can take this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic