Re: Validation Framework and DispatchAction

2006-12-28 Thread Wendy Smoak

On 12/28/06, Andy Foster <[EMAIL PROTECTED]> wrote:


This should solve my problem as each submitaction that requires validation
validates the same set of data.

However this will not work if there are three methods create and update both
need to validate but each validate against a different set of parameters and
the third submitaction does not validate.


To validate against a different set of parameters for each dispatched
method, consider how ValidatorForm and ValidatorActionForm work.
ValidatorForm keys off of the form name, while ValidatorActionForm
keys off the path.

You appear to already be using ValidatorActionForm, because you have
  
instead of
  

If you want to invent a new way to map requests to validation rule
sets, I think all you need to do is subclass ValidatorForm and
override getValidationKey().  Try having it return the value of the
parameter you're using for method dispatching, then use that for the
 in validation.xml.

Seems reasonable anyway... I haven't played with this in a while.

--
Wendy

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Validation Framework and DispatchAction

2006-12-28 Thread Ed Griebel

Use a "page" field in your form (set this in your action class before
you call form.validate()) and set page="x" in your validation.xml
file. The example below shows using a HTML hidden field "page", which
is a different way to set this page variable.

http://struts.apache.org/1.x/struts-extras/dispatchValidator.html

HTH,
-ed

On 12/28/06, Andy Foster <[EMAIL PROTECTED]> wrote:

Thanks Wendy,

Switching validation off in struts-config and invoking manually in each
method where required will work. This can be done as follows:

// validate
ActionMessages errors = form.validate(mapping,request);
if ( errors != null && !errors.isEmpty() )
{
saveErrors(request, errors);
return mapping.getInputForward();
}

This should solve my problem as each submitaction that requires validation
validates the same set of data.

However this will not work if there are three methods create and update both
need to validate but each validate against a different set of parameters and
the third submitaction does not validate.

Regards

Andy

-Original Message-
From: Wendy Smoak [mailto:[EMAIL PROTECTED]
Sent: 28 December 2006 16:46
To: Struts Users Mailing List
Subject: Re: Validation Framework and DispatchAction

On 12/28/06, Andy Foster <[EMAIL PROTECTED]> wrote:

> This validates at the action mapping level so in the above case it
validates
> on update as well as create.
>
> How do you validate just against the create submitaction of the
> DispatchAction mapping?

I would suggest turning off the automatic validation, and calling it
manually when needed.

Here's an article about it (though the motivation here is different):
   http://www.learntechnology.net/validate-manually.do

--
Wendy

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-MY Original Message-
Hi all,

This is probably a common question but have struggled to find an answer so
apologies if I have missed the obvious. Below is an example of issue:

I have a page that uses a single form to hold all the display data but can
perform the following multiple submit actions:

Create - create as a new object
Update - update the original

The page calls "/process_object.do" which is represented by a DispatchAction
that has a method for each submit action. This is simple to implement and is
all working fine.

I now turn to the validation framework I want to specify a rule to validate
the name to 3 characters only when the submitaction is create and this is my
problem. So the basic validation.xml entry is:






minlength
3




This validates at the action mapping level so in the above case it validates
on update as well as create.

How do you validate just against the create submitaction of the
DispatchAction mapping?

Regards,

Andy Foster


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Validation Framework and DispatchAction

2006-12-28 Thread Andy Foster
Thanks Wendy,

Switching validation off in struts-config and invoking manually in each
method where required will work. This can be done as follows:

// validate
ActionMessages errors = form.validate(mapping,request);
if ( errors != null && !errors.isEmpty() ) 
{
saveErrors(request, errors);
return mapping.getInputForward();
}

This should solve my problem as each submitaction that requires validation
validates the same set of data. 

However this will not work if there are three methods create and update both
need to validate but each validate against a different set of parameters and
the third submitaction does not validate.

Regards

Andy

-Original Message-
From: Wendy Smoak [mailto:[EMAIL PROTECTED] 
Sent: 28 December 2006 16:46
To: Struts Users Mailing List
Subject: Re: Validation Framework and DispatchAction

On 12/28/06, Andy Foster <[EMAIL PROTECTED]> wrote:

> This validates at the action mapping level so in the above case it
validates
> on update as well as create.
>
> How do you validate just against the create submitaction of the
> DispatchAction mapping?

I would suggest turning off the automatic validation, and calling it
manually when needed.

Here's an article about it (though the motivation here is different):
   http://www.learntechnology.net/validate-manually.do

-- 
Wendy

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-MY Original Message-
Hi all,

This is probably a common question but have struggled to find an answer so
apologies if I have missed the obvious. Below is an example of issue:

I have a page that uses a single form to hold all the display data but can
perform the following multiple submit actions:

Create - create as a new object
Update - update the original

The page calls "/process_object.do" which is represented by a DispatchAction
that has a method for each submit action. This is simple to implement and is
all working fine.

I now turn to the validation framework I want to specify a rule to validate
the name to 3 characters only when the submitaction is create and this is my
problem. So the basic validation.xml entry is:






minlength
3

   
   

This validates at the action mapping level so in the above case it validates
on update as well as create. 

How do you validate just against the create submitaction of the
DispatchAction mapping?

Regards,

Andy Foster


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Validation Framework and DispatchAction

2006-12-28 Thread Wendy Smoak

On 12/28/06, Andy Foster <[EMAIL PROTECTED]> wrote:


This validates at the action mapping level so in the above case it validates
on update as well as create.

How do you validate just against the create submitaction of the
DispatchAction mapping?


I would suggest turning off the automatic validation, and calling it
manually when needed.

Here's an article about it (though the motivation here is different):
  http://www.learntechnology.net/validate-manually.do

--
Wendy

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]