File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes what's wrong wtih this validation code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "what Watch "what New topic
Author

what's wrong wtih this validation code

Vicky Pandya
Ranch Hand

Joined: Dec 16, 2004
Posts: 148
I think I am doing something terribly silly as I don't know why following simple validation doesn't work. This is very simple validation but when I hit submit on logon page w/o username, no validation takes place. FYI: I have all required jars in path. using tomcat 4-1-24 with struts 1.2.4

part of struts-config.xml
<form-bean name="logonForm" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="user" type="java.lang.String"/>
<form-property name="password" type="java.lang.String"/>
</form-bean>

<!-- logon Action -->
<action path="/logonAction" type="com.action.LogonAction"
name="logonForm"
scope="request"
validate="true" input="/jsp/logon.jsp">
<forward name="success" path="risksearch.page"/>
</action>

<message-resources parameter="resources.MessageResources" />

<plug-in className="org.apache.struts.tiles.TilesPlugin">
<set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />
<set-property property="moduleAware" value="true"/>
</plug-in>

<!-- Validator Configuration -->
<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="true"/>
</plug-in>

part of validation.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">

<form-validation>
<formset>
<form name="logonForm">
<field property="user" depends="required">
<arg0 key="logonForm.user"/>
</field>
</form>
<form name="searchForm">
<field property="freeText" depends="required">
<arg0 key="searchForm.freeText.displayname"/>
</field>
</form>
</formset>
</form-validation>

part of logon.jsp
<%@page language="java"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<html:html><head><title>Please, Sign in !</title><head>
<body>
<html:errors/>

<logic:messagesPresent>
<bean:message key="errors.header"/>
<ul>
<html:messages id="error">
<li><bean:write name="error"/></li>
</html:messages>
</ul><hr />
</logic:messagesPresent>

<html:form action="logonAction" focus="userName">
<table border="0" width="100%">
<tr>
<th align="right"><bean:message key="logonForm.user"/>: </th>
<td align="left"><html:text property="user"/></td>

part of validator-rules.xml
!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">

<form-validation>
<global>
<validator name="required"
classname="org.apache.struts.validator.FieldChecks"
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">
Vicky Pandya
Ranch Hand

Joined: Dec 16, 2004
Posts: 148
got this sucker working. it was issue with strus class in validator-rules.xml

"org.apache.struts.validator.FieldChecks" class
and its method "validateRequired" with parameters Object, ValidatorAction etc...
In my case, 4th parameter was set to "ActionErrors" instead of "ActionMessages"
which doesnt reflect changes in struts 1.2
below is correct definition.

<validator name="required"
classname="org.apache.struts.validator.FieldChecks"
method="validateRequired"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
javax.servlet.http.HttpServletRequest"
msg="errors.required">
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
i can't believe i missed that...i migrated a bunch of apps from 1.1 to 1.2.4 a while ago and had to changed all ActionErrors to ActionMessages (as a matter of fact, i posted the migration process here before). it didn't cross my mind that you are using old validator-rules.xml against a later version. good job.


-/a<br />certified slacker...yes, my last name is 'do' - <a href="http://www.luckycouple.com" target="_blank" rel="nofollow">luckycouple.com</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what's wrong wtih this validation code
 
Similar Threads
Struts Validator not validating on the server-side
Error using Struts Validator
LookupDispatch action with validator
What Are the Causes for Validation Not Doing Anything?
Validation framework is not working