aspose file tools*
The moose likes Struts and the fly likes Struts 2 validation.xml not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2 validation.xml not working" Watch "Struts 2 validation.xml not working" New topic
Author

Struts 2 validation.xml not working

Fletcher Munson
Ranch Hand

Joined: May 16, 2007
Posts: 31
I can't seem to get Struts 2 validations to work. I have been converting from Strust 1 to Struts 2. So far I've refactored all the code (for this particular module) on the back end, rewrote the jsp using Struts 2 notations, and wired up the xml (aside from the abc-validation.xml). Everything runs just fine. If there is an error not generated by user input (i.e. file format problem) I can get that message to come out, so I know my error messages work. I try to add the abc-validation.xml for my abc class, but the validations never catch. The input field types I'm using are of select (x3) and file(x1). The selects all use numbers (default 0), and the file is just a file path (default blank). I set my validation.xml (below) to have a min of 1 for the selects, and required for the file field. So when I hit submit I expect something to come back with out hitting my action class, but it doesn't. My action does extend ActionSupport and implements RequestAware. Can anyone point me in the right direction?

UserFileLoadAction-validation.xml:



struts.xml:



SCJP 5, SCWCD 1.4
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

First off, and (probably) not related, is that your per-action interceptor configuration is way off... you're defining a *whole* bunch of interceptors twice (or more, in several cases). As shown you've got the entire "paramsPrepareParamsStack" *plus* the "defaultStack" *plus* and additional "validation" interceptor. This is almost certainly not what you want.

Secondly, for the default validation process to work you must have a result named "input"--that's the result a failed validation will return by default. Your "error" result is probably what you'd want to be "input" instead.

I'd start with those two issues first.
Fletcher Munson
Ranch Hand

Joined: May 16, 2007
Posts: 31
So I made the suggested changes, and it still isn't working. My new file is below.

struts.xml:

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

The .monitor.Monitor tile (the "input" result) has the form using non-simple-theme input tags and/or the field error msg tag? In the previous version it looked like all that was in the .user.LoadFile tile.

I'd have to write a quick sanity check beyond that, which I can't do at the moment--maybe later in the day though.
Fletcher Munson
Ranch Hand

Joined: May 16, 2007
Posts: 31
Thanks for the quick replies.

Sorry about that confusion .user.LoadFile is just a mask. There are some paths that contain the name of my company so for my own job security (especially in todays market) I decided to change all the names. Anyhow it is just a tile reference that maps the input jsp.

Fletcher Munson
Ranch Hand

Joined: May 16, 2007
Posts: 31
I've resolved this. It was an awful mistake. I misspelled my file name. Expensive lesson.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Ah, good catch; I missed that too.
 
 
subject: Struts 2 validation.xml not working