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:

<form name="/process_object">
        <field property="name" depends="minlength">
                <arg0 key="name.heading"/>
                <arg1 key="${var:minlength}" name="minlength"
resource="false"/>
                <var>
                        <var-name>minlength</var-name>
                        <var-value>3</var-value>
                </var>
        </field>
</form>

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]

Reply via email to