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

Struts validation not working

 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I'm new to struts programming and was trying to create a small form which uses the most basic required validation.

When I write this to include validator plugin everything works fine:


But when I write this the validation doesn't happen.


Is there some property or something that I need to set in order to use the local validator-rules.xml file.

Please Help
[ November 01, 2007: Message edited by: Asha Pathik ]
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Asha Pathik
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Please help me with struts validation.
 
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 am not sure...your not working example looks exactly like what I have (I am using Struts 1.1). Do you see any errors at startup? I suspect that the problem is with an error in your validator-rules.xml file, or that the file does not exist in the specified directory.

- Brent
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Is there some property or something that I need to set in order to use the local validator-rules.xml file.



I suspect that the compiled version of your older code is being referenced by the server...

Could you clear your server's temp dir (where it stores the class file and all that...), recompile the files again, restart server and test it?
 
Asha Pathik
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Brent,
In Tomcat Server logs, I'm getting no error but there is one warning regarding resource file:


Bhasker,
I tried deleting all files and restarting the server but still I'm not able to do validation using my validator-rules file.

For your reference I'm pasting all the files:
struts-config.xml


AddressJAvascriptValidation.JSP file



Validation.xml


Alll the xmls. are in WEB-INF folder and MessageResource.properties file is in /web-inf/src/java folder.

Please help

[ November 11, 2007: Message edited by: Asha Pathik ]
[ November 11, 2007: Message edited by: Asha Pathik ]
 
Bhaskar Reddy
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You mentioned


MessageResource.properties file is in /web-inf/src/java folder


but in your struts-config.xml, you've specified


I think you must update the struts-config.xml like something below -


Also, please check the filename, is it MessageResource.properties or MessageResources.properties??
[ November 12, 2007: Message edited by: Bhaskar Reddy ]
 
Bhaskar Reddy
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, w.r.t. the validator-rules.xml not being used, can you create a folder under WEB-INF (say 'config') and put both validation.xml & validator-rules.xml there?
And then update your struts-config.xml like below -


Please verify if your server contains the appropriate xml file...
[ November 12, 2007: Message edited by: Bhaskar Reddy ]
 
Asha Pathik
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bhasker,

Finally I'm able to do validation using local validator-rules.xml but there is one more problem.. the error messages are getting printed on the same page instead of appearing a alert message box.

Any idea how to solve this one ...

 
Asha Pathik
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Can someone please copy validator-rules.xml file here? I think the problem is with my xml file because none of changes are getting saved.

Regards
Asha
[ November 13, 2007: Message edited by: Asha Pathik ]
 
Bhaskar Reddy
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your jsp page you are using -


Struts displays error messages (if any) in the page where html:errors is being used.

the error messages are getting printed on the same page instead of appearing a alert message box.



If you want the error messages to get printed in an alert box, please change your code as provided in the link below -
display error in alert box
 
Asha Pathik
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bhaskar, everything is working now.
 
Asha Pathik
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bhaskar,

Again my validation is not working properly. Changes in MessageResources.properties file is displaying message like this.



Plus message in alert box is a concatination of these messages and is displayed in one single line.

Please help.
 
Bhaskar Reddy
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess there is an entry missing for 'required' field validation. Please put an entry (key must be the same as that used in your validator-rules.xml for 'required' field validation) as below -


If you are using struts validation framework, please follow the instructions as provided in the framework (you may read the entire steps as outlined here).

Besides, the error object will have a list of all the errors that occurred during the validation process. You should write your own logic to separate out the field specific errors.
 
this llama doesn't want your drama, he just wants this tiny ad for his mama
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic