You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Jesus Salvo Jr." <je...@communicator.com.au> on 2005/11/17 03:04:06 UTC

Validation without using a DynaValidatorForm

Hi,

Struts 1.2.7

I have existing ActionForm and Action classes, whereby validation is done via 
the validate() method in the ActionForm bean. These are just basic 
validations.

What I want to do is get rid of the validate() method and make use of the 
validation framework ( e.g. validation.xml ) instead, and thereby allowing me 
to reuse the same validation on both server-side and client-side.

What I am confused about is that validation via the validation.xml seems only 
to work ( or so I believe after reading various documentations and samples ) 
if one uses DynaValidatorForm instead of an ActionForm.

Problem is, my Action classes relies on the ActionForm beans properties, and 
having to change to ue DynaValidatorForm means I have to change my Action 
classes to use:

	dynaForm.get( "propertyName" )

instead of:
	
	form.getPropertyName()

... and I would hate to change all of those Action classes to use a Map 
instead of a bean.

Is there a way to use the validation provided by the validation.xml without 
using a DynaValidatoForm ?

I presume I would have to use ValidatorForm instead of an ActionForm, but not 
sure how to proceed further, or how to make it work.

( Yes, I have validate="true" on my action in struts-config.xml ):

===========================

    		<form-bean name="campaignForm" 
type="com.mig.provisioning.CampaignForm"/> 	

< ....snip....>
				<action path="/addCampaign"
				        type="com.mig.provisioning.AddCampaignAction"
				        name="campaignForm"
				        scope="request"
				        validate="true"
				        >
				        <forward name="success" path="/viewcampaign.jsp"/>
				        <forward name="failure" path="/newcampaign.jsp"/>
				</action>  

===========================

I also have the following in validation.xml:
===========================

    <formset>
        <form name="/addCampaign">
            <field
                property="name"
                depends="required">
                    <arg key="campaignForm.campaignName"/>
            </field>
            <field
                property="countryCode"
                depends="required">
                    <arg key="campaignForm.countryCode"/>
            </field>            
            <field
                property="sourceAddress"
                depends="required">
                    <arg key="campaignForm.sourceAddress"/>
            </field>            
            <field
                property="moRate"
                depends="required,double">
                    <arg key="campaignForm.moRate"/>
            </field>            
            <field
                property="mtRate"
                depends="required,double">
                    <arg key="campaignForm.mtRate"/>
            </field>            
        </form>
===========================


I saw in this article about ValidatorServlet:

	http://www.onjava.com/pub/a/onjava/2002/11/13/jsp_servlets.html

... but is was for Struts 1.1, and there is no ValidatorServlet for 1.2.7


Regards,

John

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


Re: Validation without using a DynaValidatorForm

Posted by "Jesus Salvo Jr." <je...@communicator.com.au>.
On Thursday 17 November 2005 13:24, Wendy Smoak wrote:
> On 11/16/05, Jesus Salvo Jr. <je...@communicator.com.au> wrote:
> > Struts 1.2.7
> >
> > What I am confused about is that validation via the validation.xml seems
> > only to work ( or so I believe after reading various documentations and
> > samples ) if one uses DynaValidatorForm instead of an ActionForm.
>
> I haven't used it, but there is a "plain" ValidatorForm:
> http://struts.apache.org/struts-core/apidocs/org/apache/struts/validator/Va
>lidatorForm.html
>
> Would that work for you?
>

Yes. I have extended the form bean to use ValidatorForm.

What was missing in all my search was the you have to specify the input 
attribute on the action element. The value of the input attribute is a URI to 
forward to if validation fails.

Thanks.

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


Re: Validation without using a DynaValidatorForm

Posted by Wendy Smoak <ws...@gmail.com>.
On 11/16/05, Jesus Salvo Jr. <je...@communicator.com.au> wrote:

> Struts 1.2.7
>
> What I am confused about is that validation via the validation.xml seems only
> to work ( or so I believe after reading various documentations and samples )
> if one uses DynaValidatorForm instead of an ActionForm.

I haven't used it, but there is a "plain" ValidatorForm:
http://struts.apache.org/struts-core/apidocs/org/apache/struts/validator/ValidatorForm.html

Would that work for you?

--
Wendy

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