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

Form Validation using xml in struts2

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ravindra,

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

regards,
hemanth.
directory-structure.GIF
[Thumbnail for directory-structure.GIF]
Directory structure
 
Ravindra B Pawar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
There are 29 Knuts in one Sickle, and 17 Sickles make up a Galleon. 42 tiny ads in a knut:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic