struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shannon, Andrew" <>
Subject RE: How to avoid validation if request was done by GET method?
Date Fri, 27 Mar 2009 12:40:04 GMT
We also have a pattern for many situations where we encapsulate our
page-centric handling into a single action where for example a GET into
the action sets up the page, and a POST to the same action for form
handling but to a different method in the action.  Our approach to avoid
validation on the Get is that we have taken to writing most of our
validation as java code in the validate() method of an action that
implements validation aware, and have gotten away from plugging in
validators to objects for this particular reason.  So what we do is:

public void validate() {
	String actionMethod =

(actionMethod.equals("myActionMethodConfiguredAsTheFormPostTarget")) {
		// do some validation

This also allows us to delegate validation to other classes needed to
handle more complex validation scenarios.

-----Original Message-----
From: benjamin haimerl [] 
Sent: Thursday, March 26, 2009 1:34 PM
To: Struts Users Mailing List
Subject: Re: How to avoid validation if request was done by GET method?

hi boraldo

a very simple way should be:


YourActionConnetedToTheFormAction extends Action..{


String qString = request.getQueryString();
if(qString!=null && paramsFound(...))
   // *paramsFound() = check if your formParams were given by query
else {
//check if your formBean is set (depends on the scope you have set in 
your struts-config.xml)
  if(request.getAttribute(yourForm)!=null) {
  yourForm.validate() {


should work ;)

boraldo wrote:
> I have a form. And I want to have one url for form itself and for
> 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 ?

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message