This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Struts and the fly likes appfuse validation problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "appfuse validation problem" Watch "appfuse validation problem" New topic
Author

appfuse validation problem

K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2379
    
    7

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.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Moving to Struts.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Sep 13, 2007
Posts: 2379
    
    7

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

Joined: Sep 29, 2008
Posts: 12617

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 agree. Here's the link: http://aspose.com/file-tools
 
subject: appfuse validation problem