• 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

How to avoid validation if request was done by GET method?

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a form. And I want to have one url for form itself and for submitting it.
Controller should look at method and if it is GET, show form, if POST - make validations and so on.

How can I do it ?
 
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
What version of Struts?
 
Boris Romashov
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Struts 2, I also use convention plugin.
 
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
There's nothing to do that built-in; what I've usually done (because it's really easy :) is use the @Action annotation to map either the input method or a "process" method that'll do validation. I suppose you could do something similar with an interceptor, although I've never tried it with Convention, only a "plain" S2 app.
 
Boris Romashov
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>> what I've usually done is use the @Action annotation to map either the input method or a "process" method that'll do validation.

I don't understand anything
Could you explain more precisely, please.
 
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
Rather than specifically checking the request type ("GET" or "POST") I've just had different action mappings to display the form and process the form submission.

In Struts 1 I had a base action class that checked for GET/POST and would call validation manually on a POST. Struts 2's architecture makes this impractical on the action side.

In Struts 2 there are (at least) two simple approaches: interceptor side, and action mapping side.

On the interceptor side it's trivial to tweak the validation interceptor to skip validation on GET requests--essentially creating an exact duplicate of the shipping validation interceptor plus a request type check.

On the action mapping side you could display the form with one action mapping and process it with another. The initial form display could be handled by the input() method (which validation skips) and processed with a process() (or re-mapped execute() method?) method, which validation wouldn't skip.

I don't think I've explained myself well--feel free to follow up.
 
Boris Romashov
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please, look at my 1st post.

>> I want to have one url for form itself and for submitting it.

How does your approach satisfies this requirement ?
 
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
It doesn't; I guess you'll have to use the other suggestion I made of creating or modifying an interceptor.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic