• 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

Struts2 XML validation is not working

 
Ranch Hand
Posts: 113
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Guys,

I am using Struts2 version (2.3.20) and also tried to downgrade to 2.3.15. But my declarative validations in XML are not working. Attached are the files. Could anyone please help.

struts.xml
------------


index.jsp

EmployeeAction.java
-------------------------


EmpSuccess.jsp
------------------------


EmployeeAction-valildation.xml
--------------------------------------



web.xml
------------


Issue: While I am not filling up the form, no validation is working and it is going to EmpSuccess.jsp

What wrong I am doing here
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where is EmployeeAction-valildation.xml located?
 
Souvik Dasgupta
Ranch Hand
Posts: 113
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

It is in the same package along with the EmployeeAction.java
 
Souvik Dasgupta
Ranch Hand
Posts: 113
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am using Netbeans. Please find the project structure attached.

Struts2.jpg
[Thumbnail for Struts2.jpg]
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like the doctype you are using in your validation.xml file is not accessible. According to the Struts documentation, the doctype for validation files is:

 
Souvik Dasgupta
Ranch Hand
Posts: 113
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I tried it. But still the issue persists.
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can try with the following
 
Souvik Dasgupta
Ranch Hand
Posts: 113
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This does not work either. It throws Freemarker template error at runtime.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

bablu singh wrote:You can try with the following



That attribute turns on client side validation.

Since you are using Struts 2.3.x, you should update the doctype of your Struts.xml as well:


The typical problem I have with validation is matching the action name, action class and method in the validation file name.
I would take the following steps:
1. rename the action name in struts.xml to something other than the action class name (i.e. register).
2. change the validation file name to match the action class name and the action name (i.e. EmployeeAction-register-validation.xml)
3. place a debug statement in the action.execute method (if this is printed out, we know that validation didn't work. It rules out having a bad mapping for the input result in struts.xml)
4. reduce the validation to a single field and a single, simple validator (like "required"). This should rule out any other errors in the validation file.
Do that and check your server log files to see if there's any errors processing the files.
 
Souvik Dasgupta
Ranch Hand
Posts: 113
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I did 1 to 4. But found that log statement is not being printed.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That would indicate to me that validation IS working and the problem is elsewhere. Is the log message printed out if you put something in the required field?
 
Souvik Dasgupta
Ranch Hand
Posts: 113
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

No it is not. It is showing the entered value in the EmpSuccess.jsp. But sysout inside execute( ) is not being printed.
 
Souvik Dasgupta
Ranch Hand
Posts: 113
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joe,

I have been able to resolve the issue.It was a problem regarding the location of the validation.xml file. It should go under src/main/resources/<my package>. Here goes the correct structure. However, Thanks a ton for spending your time.

struts2.jpg
[Thumbnail for struts2.jpg]
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, are you using Maven to build? The "best practice" for Maven is to put non-source files to be in the "resources" directory. I always use Ant and the "best practice" for it is to have the source and validation files in the same directory, since that is where they will be in the WAR.
 
Please do not shoot the fish in this barrel. But you can shoot at this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic