You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Vicky <ja...@yahoo.com> on 2005/06/23 16:25:17 UTC

Validation while using LookupDispatchAction

My action class extends LookupDispatchAction, which
has different methods in it. In struts-config.xml i
have parameter method as we all know. My problem is;
in my validation.xml i do have to perform different
validations for different methods, how do I
distinguish or find out which method is called to
perform validation for that method only?

struts-config.xml
<form-bean name="myForm"
type="org.apache.struts.validator.DynaValidatorActionForm">
   <form-property name="freeText"
type="java.lang.String"/>

....
</form-bean>

<action path="/myAction" type="com.action.MyAction"
name="myForm" validate="true" parameter="method">
<forward..
</action>

validation.xml

<form-validation>
    <formset>
        <form name="/myaction.do">
            <field property="freeText"
depends="required">
               <arg0 key="myForm.freeText.name"/>
            </field>
        </form>
     </formset>
</form-validation>

in above code in validaton.xml i need to pass method
name for which i want this validation to take place
not for all methods. Something like <form
name="/myAction.do?method="methodName">

how do I do this? or any other way. I would appreciate
prompt response with examples.

Thanks in advance,




		
__________________________________ 
Yahoo! Mail Mobile 
Take Yahoo! Mail with you! Check email on your mobile phone. 
http://mobile.yahoo.com/learn/mail 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Validation while using LookupDispatchAction

Posted by Andrew Tomaka <at...@gmail.com>.
You might be interested in checking out ValidatorLookupDispatchAction
(http://struts.whoisandy.com/archives/2005/05/27/validatorlookupdispatchaction.php).
 I stumbled across, but never actually used it.

~ Andrew Tomaka

On 6/23/05, Wendy Smoak <ja...@wendysmoak.com> wrote:
> From: "Vicky" <ja...@yahoo.com>
> >
> > But having different actions in struts-config. how
> > would I call them in my jsp html:form ? because right
> > now I have only one action in jsp <html:form
> > action="myAction"> and then for each button i have
> > property="method".. in jsp
> >
> > in struts-config for this action mapping I have
> > parameter="method"
> >
> > Did I miss anything in here?
> 
> DynaValidatorActionForm wants to validate based on the path, so you have to
> give it different paths to work with.  If you can't or don't want to have
> different paths mapped to the same action and form, then a different
> solution is in order.
> 
> I doubt you are alone... I wonder if someone has written a flavor of
> ValidatorForm that uses the dispatch parameter to switch validation.  None
> comes to mind, but search the list archives and the Wiki to see if there is
> already something out there.
> 
> And of course you're always free to override 'validate' in your form bean
> and make it do exactly what you want, or to turn off automatic validation
> altogether and call it from your Action when and where you want it to
> happen.
> 
> If you're having trouble deciding what the best approach would be, tell us
> more about your project and I'm sure there will be no shortage of opinions.
> (Hey, Mark, welcome back! So, tell us how you REALLY feel about Validator...
> ;) )
> 
> --
> Wendy Smoak
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Validation while using LookupDispatchAction

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Vicky" <ja...@yahoo.com>
>
> But having different actions in struts-config. how
> would I call them in my jsp html:form ? because right
> now I have only one action in jsp <html:form
> action="myAction"> and then for each button i have
> property="method".. in jsp
>
> in struts-config for this action mapping I have
> parameter="method"
>
> Did I miss anything in here?

DynaValidatorActionForm wants to validate based on the path, so you have to
give it different paths to work with.  If you can't or don't want to have
different paths mapped to the same action and form, then a different
solution is in order.

I doubt you are alone... I wonder if someone has written a flavor of
ValidatorForm that uses the dispatch parameter to switch validation.  None
comes to mind, but search the list archives and the Wiki to see if there is
already something out there.

And of course you're always free to override 'validate' in your form bean
and make it do exactly what you want, or to turn off automatic validation
altogether and call it from your Action when and where you want it to
happen.

If you're having trouble deciding what the best approach would be, tell us
more about your project and I'm sure there will be no shortage of opinions.
(Hey, Mark, welcome back! So, tell us how you REALLY feel about Validator...
;) )

-- 
Wendy Smoak


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Validation while using LookupDispatchAction

Posted by Vicky <ja...@yahoo.com>.
Wendy,

But having different actions in struts-config. how
would I call them in my jsp html:form ? because right
now I have only one action in jsp <html:form
action="myAction"> and then for each button i have
property="method".. in jsp

in struts-config for this action mapping I have
parameter="method"

Did I miss anything in here?

Thanks,


--- Wendy Smoak <ja...@wendysmoak.com> wrote:

> From: "Vicky" <ja...@yahoo.com>
> 
> > My action class extends LookupDispatchAction,
> which
> > has different methods in it. In struts-config.xml
> i
> > have parameter method as we all know. My problem
> is;
> > in my validation.xml i do have to perform
> different
> > validations for different methods, how do I
> > distinguish or find out which method is called to
> > perform validation for that method only?
> 
> Because you're using DynaValidator_Action_Form, the
> framework will match up
> the <action> 'path' attribute from struts-config.xml
> with the <form> 'name'
> attribute from validation.xml.
> 
> I do it by having different URL patterns mapped to
> the same
> LookupDispatchAction using the same
> DynaValidatorActionForm.
> 
> In the <action> tag, only the 'path' and 'input'
> differ (so
> 'getInputForward()' works, no matter which path you
> came in with, you go to
> the right form-- it's a four-step wizard.)
>    <action
>             path="/denRegister"
>             type="edu.example.RegisterAction"
>             name="registerForm" ...
>             input="den.register.step1"> ...</action>
>    <action
>             path="/denRegister3"
>             type="edu.example.RegisterAction"
>             name="registerForm" ...
>             input="den.register.step3"> ...</action>
> 
> Then in validation.xml, you use the path for the
> form "name" (which is
> slightly confusing...):
> <form name="/denRegister"> ... </form>
> <form name="/denRegister3">... </form>
> 
> And then you can have different fields validated for
> different paths, even
> though it's the same Action and the same Form.  All
> my forms are POSTed, so
> I wouldn't have had ?parameter=someText in any case.
> 
> HTH,
> -- 
> Wendy Smoak
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 
> 



		
____________________________________________________ 
Yahoo! Sports 
Rekindle the Rivalries. Sign up for Fantasy Football 
http://football.fantasysports.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Validation while using LookupDispatchAction

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Vicky" <ja...@yahoo.com>

> My action class extends LookupDispatchAction, which
> has different methods in it. In struts-config.xml i
> have parameter method as we all know. My problem is;
> in my validation.xml i do have to perform different
> validations for different methods, how do I
> distinguish or find out which method is called to
> perform validation for that method only?

Because you're using DynaValidator_Action_Form, the framework will match up
the <action> 'path' attribute from struts-config.xml with the <form> 'name'
attribute from validation.xml.

I do it by having different URL patterns mapped to the same
LookupDispatchAction using the same DynaValidatorActionForm.

In the <action> tag, only the 'path' and 'input' differ (so
'getInputForward()' works, no matter which path you came in with, you go to
the right form-- it's a four-step wizard.)
   <action
            path="/denRegister"
            type="edu.example.RegisterAction"
            name="registerForm" ...
            input="den.register.step1"> ...</action>
   <action
            path="/denRegister3"
            type="edu.example.RegisterAction"
            name="registerForm" ...
            input="den.register.step3"> ...</action>

Then in validation.xml, you use the path for the form "name" (which is
slightly confusing...):
<form name="/denRegister"> ... </form>
<form name="/denRegister3">... </form>

And then you can have different fields validated for different paths, even
though it's the same Action and the same Form.  All my forms are POSTed, so
I wouldn't have had ?parameter=someText in any case.

HTH,
-- 
Wendy Smoak



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org