aspose file tools
The moose likes Struts and the fly likes Problem with Validator Framework Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Reply Bookmark "Problem with Validator Framework" Watch "Problem with Validator Framework" New topic
Author

Problem with Validator Framework

sameer meher
Greenhorn

Joined: Jun 06, 2008
Posts: 10
I am new to Struts.I tried implementing Validator Framework concept, but its not working..I have taken the code from RoseIndia.net..
Here is the code snippet:
-----------------------
index.jsp
-------------
<html:link page="/AddressJavascriptValidation.jsp">Checking the Validator Framework</html:link><br>
AddressJavascriptValidation.jsp
--------------------------------
<body bgcolor="white">

<html:form action="/AddressJavascriptValidation" method="post" onsubmit="return validateAddressForm(this);">

<div align="left">
<p>
<bean:message key="AddressValidator.title"/>
--some code for displaying controls----------
</table>
</div>

<html:javascript formName="AddressForm" dynamicJavascript="true" staticJavascript="true" />

</html:form>
I have added the validator.xml and validation-rules.xml inside WEB/INF.
When I am checking the source code, the script is not getting displayed in the jsp page....I don't know what I have missed out....
:roll:


Regards,<br />Sameer
yan yan
Greenhorn

Joined: Aug 01, 2007
Posts: 16
Hi Sameer,

Please post your validation.xml.


In your form-validation, it should have something like this:

<form name="AddressForm">
<field property="username" depends="required">
<arg key="prompt.key"/>
</field>
</form>

*Make sure your "prompt.key" is in your message resource bundle.

Make sure also that that in your struts-config.xml, validate attribute in your action is set to true. Something like this.

<action
name="AddressForm"
path="/AddressJavascriptValidation"
scope="request"
type="com.rms.struts.action.AdressAction"
input="AddressJavascriptValidation.jsp"
parameter="parameter"
validate="true">
<forward name="initialize" path="AddressJavascriptValidation.jsp" />
<forward name="failure" path="AddressJavascriptValidation.jsp"/>

</action>


Hope this helps.
ianne
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2896
    
    1

You missed out the form definition in validation.xml for "AddressForm" , and important thing is that the first letter for form name should be small , like "addressForm" ..

add validation for addressForm in validation.xml like ..



Hope this help !!


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
sameer meher
Greenhorn

Joined: Jun 06, 2008
Posts: 10
Here is the Validation.xml code:
--------------------------------
<form name="addressForm">
<field property="name"
depends="required">
<arg key="AddressForm.name"/>
</field>
<field property="address"
depends="required">
<arg key="AddressForm.address"/>
</field>
<field property="emailAddress"
depends="required">
<arg key="AddressForm.emailAddress"/>
</field>
</form>
yan yan
Greenhorn

Joined: Aug 01, 2007
Posts: 16
Hi Sameer,

The formname should be the same as the one declared in the struts-config.xml
form bean property name attribute. The first letter of the name should be in small letter.

try changing "AddressForm" to "addressForm" in this line code.

Not:
<html:javascript formName="AddressForm" dynamicJavascript="true" staticJavascript="true" />

Correct:
<html:javascript formName="addressForm" dynamicJavascript="true" staticJavascript="true" />
sameer meher
Greenhorn

Joined: Jun 06, 2008
Posts: 10
Hi All,
I have tried different approaches as all of you have suggested.
My Form bean name is: AddressForm.java

struts-config.xml:
<action
path="/AddressJavascriptValidation"
type="struts.example.AddressValidatorAction"
name="AddressForm"
scope="request"
validate="true"
input="/AddressJavascriptValidation.jsp">
<forward name="success" path="/SuccessValidator.jsp"/>
</action>
In validation.xml:
form name is "addressForm"
<form name="addressForm">
<field property="name"
depends="required">
<arg key="AddressForm.name"/>
</field>
<field property="address"
depends="required">
<arg key="AddressForm.address"/>
</field>
<field property="emailAddress"
depends="required">
<arg key="AddressForm.emailAddress"/>
</field>
</form>
AddressJavascriptValidation.jsp:
<html:form action="/AddressJavascriptValidation" method="post" onsubmit="return validateAddressForm(this);"> while submitting the form

<html:javascript formName="addressForm" dynamicJavascript="true" staticJavascript="true" /> adding the script at the bottom of the jsp page

This is all about the configuration....I am not getting the desired output....Can anyone suggest some alternative.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2896
    
    1



put this above body tag , and see ..

I am not getting the desired output..


Pl be specific, and post what exactly you want and what you are getting ?
sameer meher
Greenhorn

Joined: Jun 06, 2008
Posts: 10
Hi,

As suggested for placing the code:


above the body tag, I tried this approach also, but it is not working.

Not getting desired results mean,the Validator concept is not working .When I am checking the source code of the jsp in the browser, the added code snippet of validation.xml is not getting displayed.
This is where I am getting confused where I am doing the mistake.
Can anyone send their email id, so that i better send the files to you, that will give a clear picture I think.

Thanks for your suggestions,
yan yan
Greenhorn

Joined: Aug 01, 2007
Posts: 16
Hi Sameer,

In your struts-config.xml,

<form-beans>
<form-bean name="addressForm" type="struts.example.AddressForm">
</formbean>

<action
path="/AddressJavascriptValidation"
type="struts.example.AddressValidatorAction"
name="addressForm"
scope="request"
validate="true"
input="/AddressJavascriptValidation.jsp">
<forward name="success" path="/SuccessValidator.jsp"/>
</action>


In the action class, change the name attribute to "addressForm".
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Problem with Validator Framework
 
Similar Threads
Validator Struts not is loading in browser
Struts validation not working
Validator Struts not is loading in browser
Problem with html:form when session invalidated
Validation framework not working for login screen