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

Struts2 & validation [SOLVED]

Posts: 9
Eclipse IDE Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 clientAction.save() 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.java 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 clientAction.properties :

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
Posts: 9
Eclipse IDE Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic