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

appfuse validation problem

 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

Do anyone know AppFuse? Anyway, it's a app framework that uses Spring + Struts 2 + Hibernate. I have set up the app framework and got the form, controller and able to save data to database. Then I added in the validation stuff and now my save function doesn't work. Worst off, I don't think the save function even got triggered.

JSP form


Validation xml for the action class


The action class


And in the struts config file



How to get the validation to trigger my save method in the action class? Thanks.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Struts.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
None of the field names in the validation file match the form fields.

Also, is there a particular reason you're bypassing the Struts 2 type conversion stuff and pulling request parameters out of the request directly? (This could also be leading to the validation issue.) It kind of defeats the purpose of using Struts 2.
 
K. Tsang
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see David. About the 2nd point you made, what's the correct approach to get parameters in struts 2 so that the field names match the validation xml?

When I view the html version of the form, the name value is "query.name", "query.status" and "query.query". But once I added in the validation xml file, as you said the field names not match.

As for my validation xml, I used the field-validator tags with name attribute. Such name is currently not say "query.name" but "Query Name" so that when the error messages show, it will say "Query Name is a required field" rather than "query.name is a required field".

In fact, I also have another validation xml for the model will looks exactly the same as the validation xml before but with the name attribute changed to "query.xxx". Should I change this (model) validation xml too?

Your guidance is appreciated.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please read the Struts 2 documentation regarding validation, field naming, request parameter type conversion, etc. You can't just use random, human-readable names in the validation file--that's how the validation process identifies what fields to validate. If they don't match, there's no validation.
reply
    Bookmark Topic Watch Topic
  • New Topic