| Author |
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
|
|
struts-config-Login.xml <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" /> </form-bean> <action attribute="testForm" input="/Login/test.jsp" name="testForm" path="/test" scope="request" validate="true" type="com.mycompany.struts.action.TestAction" /> <action forward="/test.jsp" path="/testindex" /> **************************************************************** validation.xml <formset> <form name="testForm"> <field property="username" depends="required"> <arg0 key="loginname" resource="false" /> </field> <field property="password" depends="required"> <arg0 key="loginpassword" resource="false" /> </field> </form> ************************************************ this is the validator-rules.xml version. $Id: validator-rules.xml,v 1.1.2.1 2006/07/01 20:50:46 eugene-proddev Exp $ *********************************************** <html:form action="/test.do" 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:submit/><html:cancel/> <html:javascript formName="testForm"/> </html:form> *************************************************** 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 ]
|
Merrill
Consultant, Sima Solutions
|
 |
 |
|
|
subject: help with validation framework
|
|
|