• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what's wrong wtih this validation code

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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">
 
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
And then we all jump out and yell "surprise! we got you this tiny ad!"
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic