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.
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.
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?
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.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com