• 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

Struts 2 validation.xml not working

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
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
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
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I made the suggested changes, and it still isn't working. My new file is below.

struts.xml:

 
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
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
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've resolved this. It was an awful mistake. I misspelled my file name. Expensive lesson.
 
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
Ah, good catch; I missed that too.
 
The only taste of success some people get is to take a bite out of you. Or this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic