• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Struts2: use EmailValidator in my validate() method?

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can I still leverage the type validators in my validate() method if I'm not using an xml file? I need to override validate() for my form validation, but still want to leverage some of the type validators from the framework. Is there an example of how to use the type validators without the xml? In Struts 1x, I would have used GenericTypeValidator - do I have to add Commons Validation to my project on top of the XWorks Validation to get type validators?

Thanks
 
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
Use annotations, or use both the XML and validate() method, or validate everything manually.
 
M Turner
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right. So if I want to validate everything in validate(), can I still leverage the Xwork type validators?

OR

Can I switch the ordering of the validation calls such that the validate() method is called first .. then the 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
I guess I don't see why you *couldn't* leverage the XWork validations manually, but I also don't understand why you wouldn't just use the annotations. I don't think I've ever used them on their own.

It's unclear to me why you'd want to run the validate() method before the XML--XML validation is for the easy stuff, like "does this field even exist" etc. Anything more complex, which is what should go in the validate() method, would depend on the XML validation anyway, at least in every use case I've ever had. You might be able to play with the order of the interceptors; off the top of my head I honestly don't remember what the default order is or which interceptor does which part of the work--you might have to poke around in the source a bit if nobody else chimes in. Worst case scenario would be a relatively minor tweak to an existing interceptor.
 
M Turner
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your thoughts Dave. My mind also went to reordering interceptors but then I knew I was in too deep...

Here's what I'm really getting at... I need to have only one error message for 3 fields - but I want to also test for whitespace which is build into requiredstring.. however that is a FieldValidator. So I tried the following:



which doesn't work and gives an error in my logs:

com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn Got result of null when trying to get Boolean.

I guess my real question is.. is there a nice way to test for whitespce in OGNL?


 
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
If I were doing it I'd try either using the complete OGNL static syntax, or just write a custom validator--they're quite easy.
 
M Turner
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm - OhGoshNL huh.. well I'm definitely new to OGNL, but the following gave the same error as above:

 
We don't have time to be charming! Quick, read this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic