Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Problem with Validator Framework

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !!
 
sameer meher
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
    Bookmark Topic Watch Topic
  • New Topic