This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

appfuse validation problem

 
K. Tsang
Bartender
Posts: 3347
12
Android Java
  • Mark post as helpful
  • send pies
  • 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.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Struts.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • 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: 3347
12
Android Java
  • Mark post as helpful
  • send pies
  • 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
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic