It's not a secret anymore!*
The moose likes Struts and the fly likes Form Validation using xml in struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Form Validation using xml in struts2" Watch "Form Validation using xml in struts2" New topic
Author

Form Validation using xml in struts2

hemanth acharya
Ranch Hand

Joined: Aug 10, 2011
Posts: 51
Hello all,

I am trying to develop an app using struts which has form with fields. I am validating the fields using the validation xml, but its not showing any error while some of the fields are empty.. Could anyone help me to find a loophole in my app, I am new to Struts, any help is greatly appreciated...


Following are the codes in my app,

My initial page with form,



My validation xml named LoginAction-Validation.xml,



My action class..




My struts.xml is the following...





Thanks and regards,
hemanth.
Ravindra B Pawar
Greenhorn

Joined: Jul 18, 2010
Posts: 9

CORRECT CODE

you have not specified the action class name

OR BETTER WAY IS TO


CHANGE THIS TO


i think you getting the point

hope this helps
hemanth acharya
Ranch Hand

Joined: Aug 10, 2011
Posts: 51
Hi Ravindra,

Thanks for the response,

I have done the changes you mentioned, its still not checking the validation xml to get the errors while the fields in the form is empty.


regards,
hemanth.
Ravindra B Pawar
Greenhorn

Joined: Jul 18, 2010
Posts: 9
The problem with your code was you were displaying the login jsp page (for first time visit to page) for that you created one dummy action login
Then you were submitting the for to same login action which was simply displaying the form again

if you submit form to the new action which will process your form and corresponding xml should be referred for the validations

for more info you can see code at
http://www.vaannila.com/struts-2/struts-2-example/struts-2-validation-using-xml-example-1.html
hemanth acharya
Ranch Hand

Joined: Aug 10, 2011
Posts: 51
Hi Ravindra,

I solved the problem...
The changes you mentioned, I had corrected, along with that i added a property file name struts.properties in which i included the constant,


where 'LoginAction' is my property file containing all the variables, eg..




regards,
hemanth.
Ravindra B Pawar
Greenhorn

Joined: Jul 18, 2010
Posts: 9
Hi Hemanth,

I have never used this property files.
Can you please show me how is you directory strutcture so that i can understand where to put
struts.PROPERTIES
LoginAction.PROPERTIES

Thanks,
Ravi
hemanth acharya
Ranch Hand

Joined: Aug 10, 2011
Posts: 51
Ravindra,

I created a new source folder for the project called 'resources' and places in that... Please find the attached image.

regards,
hemanth.



[Thumbnail for directory structure.GIF]

Ravindra B Pawar
Greenhorn

Joined: Jul 18, 2010
Posts: 9
Thanks for quick reply.

It really good idea to create new folder called resources to put these things like struts.xml and properties file.

Do you have any idea if we can put the LoginAction-validation.xml in resources folder or it has to be there with the source file LoginAction.java?

Thanks
hemanth acharya
Ranch Hand

Joined: Aug 10, 2011
Posts: 51
Ravindra,

Conventional, the 'action' and the 'validation xml' for the same should be in one folder...
I think it wont be found if its placed in 2 different folders..


regards,
hemanth.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Form Validation using xml in struts2
 
Similar Threads
problems validation.xml in struts 2
validation using Resource Bundle
problems in validation part of struts 2
Struts2 Validation Not working
Exception while running struts2 application.