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

help with validation framework

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Message for you sir! I think it is a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic