This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Boris Romashov
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • 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 ?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What version of Struts?
 
Boris Romashov
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Struts 2, I also use convention plugin.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • 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
  • 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
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • 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
  • 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
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic