my dog learned polymorphism
The moose likes Struts and the fly likes Struts2 & validation [SOLVED] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 & validation [SOLVED]" Watch "Struts2 & validation [SOLVED]" New topic

Struts2 & validation [SOLVED]

Franck Times

Joined: Sep 20, 2011
Posts: 9

Hi everyone,

I have setup a simple application to freshen up my memories of Struts 2. I think I have done whatever was needed to enjoy client side validation for user input data. The fact is it seems I've missed something. I searched, browsed, thought, etc... but still no luck

First of all, a jsp (displayClient.jsp) with a form:

in the same jsp, in the head section I added the <s:head/> as instructed by various tutorials :

so my action name is "saveClient". Let's have a look at struts.xml:

so this action is supposed to call and forward to:
success: listeClient.jsp (displaying clients)
input: The jsp at action's start
error: a jsp set to display errors & warnings

so in the package com.mysoft.lab.view there are 2 files:
clientAction-validation.xml defines a class extending com.opensymphony.xwork2.ActionSupport with appropriate setters and getters plus the action methods.
the clientAction-validation.xml contains:

the values such as errors.range are defined in a file called :

So all the fields are supposed to be required. I checked the HTML generated by tomat, the form validation calls a javascript function aimed at the input validation and the follwing line has been added by tomcat in the <head> section:

So I guess everything's fine. Except that whatever input I put in the fields (valid or not), the action is completed and a new record is added to the database. I know I should also check for validation on server side as you can never trust a client side validation but the goal here is to demonstrate client side validation...

I am pretty sure I'll be banging my head on a wall when the light will be shed on my issue but I would really appreciate if someone could point me to what I missed here for I am clueless.

Thanks a million
Franck Times

Joined: Sep 20, 2011
Posts: 9

OK I guess I know. This is not a Struts issue but rather a maven one.

Out of curiosity I looked at the deployed war. Horror there wasn't any *****-validation.xml file in the com.mysoft.lab.view class directory. I manually added these two files and reloaded the war in Tomcat.

it works !

so I have now to figure out how to tell maven I need to keep xml files along with class files....

I guess I gonna open another thread in the maven section.
I agree. Here's the link:
subject: Struts2 & validation [SOLVED]
It's not a secret anymore!