permaculture playing cards
The moose likes Struts and the fly likes help with validation framework Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "help with validation framework" Watch "help with validation framework" New topic

help with validation framework

shah rah
Ranch Hand

Joined: Jan 04, 2007
Posts: 124
Is there anything I have to do in Action class for the validation to work.

I have the validation-rule.xml and validation.xml in place under web-inf. I have a module level struts-config-Login.xml. I have a plug-in element in side struts-config-Login.xml.

I am checking for required attribute and when I press submit on the form it takes me to a blank page instead of showing errors.

My action class execute method has return null; I think it is causing return of blank page. pls help.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I believe that you would also see this behavior if you do not have an "input" attribute set on your action mapping. Check that out. If validation fails then your action should never be called. Try putting some logging messages (log4j or System.out.println) in your action. If you see the logging messages then validation is either passing or not being called. Another thing to check is that your form extends ValidatorForm.

- Brent
shah rah
Ranch Hand

Joined: Jan 04, 2007
Posts: 124

<form-bean name="testForm" dynamic = "true" type="org.apache.struts.validator.DynaValidatorActionForm">
<form-property name="password" type="java.lang.String" />
<form-property name="username" type="java.lang.String" />

type="com.mycompany.struts.action.TestAction" />
<action forward="/test.jsp" path="/testindex" />

<form name="testForm">
<field property="username" depends="required">
<arg0 key="loginname" resource="false" />

<field property="password" depends="required">
<arg0 key="loginpassword" resource="false" />
this is the validator-rules.xml version.

$Id: validator-rules.xml,v 2006/07/01 20:50:46 eugene-proddev Exp $

<html:form action="/" onsubmit="return validatetestForm(this);">
password : <html:text property="password"/><html:errors property="password"/><br/>
username : <html:text property="username"/><html:errors property="username"/><br/>
<html:javascript formName="testForm"/>

on submitting the jsp page it does not validate. It shows me a blank screen. Can anyone point me if I am doing something wrong
[ February 07, 2007: Message edited by: shah rah ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
There are three things wrong:

1- The type specified in your form-bean definition is incorrect. It should be org.apache.struts.validator.DynaValidatorForm. DynaValidatorActionForm is used if you specify an Action rather than a form name in your validation.xml file. Since you specified a form name, you must use DynaValidatorForm.

2- I don't know where you got the idea to put dynamic="true" in your form-bean definition, but it's not a valid attribute. Take it out.

3- Your Action mapping is incorrect. Change it as follows:

Also, make sure that "/Login/test.jsp" is a valid URI relative to your web context root.
[ February 07, 2007: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
I agree. Here's the link:
subject: help with validation framework
It's not a secret anymore!