• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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.
 
I got this tall by not having enough crisco in my diet as a kid. This ad looks like it had plenty of shortening:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic