You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Adam Hardy <ah...@cyberspaceroad.com> on 2003/07/02 17:39:59 UTC

DynaValidatorActionForm

I set up the Validator to do automatic validation with normal action 
forms and it worked fine.

Now I'm trying to incorporate dynaforms but I'm not having any luck. I'm 
not getting  server-side validation carried out.

I see from delving into the source code for struts and commons-validator 
that the DynaValidatorAction form .validate() method is being called, 
but that the following line:

  Form form = resources.get(locale, formName);  (578)

returns a null form and so the validation is skipped.

I've obviously missed something out on the set-up and config, but what? 
Can anybody cast a light on this? Meanwhile I'll carry on digging....

thanks
Adam

(struts 1.1 & validator 1.0.2)


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


Re: DynaValidatorActionForm

Posted by Kris Schneider <kr...@dotech.com>.
Yes, keep your form bean properties typed as String. Of course, there 
are reasonable exceptions to the rule (e.g. nested, mapped, and indexed 
properties). Otherwise, as you've observed, your form fields won't get 
repopulated with the "bad" data upon validation failures.

Adam Hardy wrote:
> Sorry, panicing for a moment there :O - OK, I see the way the javascript 
> tag works. It seems there no long validate function?
> 
> I think I have found the cause of my problem. In my dynaform definition, 
> I set my id field type to Long - and when I enter a non-Long value in 
> the form, the dynaform rejects it first and the dynaform long value 
> remains null - therefore the validateLong() method will ignore it, 
> because the validate long method can only validate a string. Is that so? 
> Should I keep all my fields as strings in my form definition?
> 
> 
> txs
> Adam
> 
> 
> 
> Kris Schneider wrote:
> 
>> Okay, it sounded like you were just concerned with server-side 
>> validation. Try
>> something like:
>>
>> <head>
>>   <html:javascript formName="/action/path" method="validateForm"/>
>>   ...
>> </head>
>>
>> <body>
>>   ...
>>   <html:form action="/action/path" onsubmit="return validateForm(this);">
>>   ...
>> </body>
>>
>> There are other best practices for organizing the "static" JavaScript, 
>> but try
>> to get something working before worrying about that...
>>
>> Quoting Adam Hardy <ah...@cyberspaceroad.com>:
>>
>>
>>> In that case then there won't be any javascript validation set up 
>>> automatically!
>>>
>>> Is that the only difference between DynaValidatorActionForm and 
>>> DynaValidatorForm?
>>>
>>> I still haven't got this working. although I'm one step further.
>>>
>>>
>>>
>>> Kris Schneider wrote:
>>>
>>>> If you're using DynaValidatorActionForm, the name attribute of the form
>>>
>>>
>>> element
>>>
>>>> in validation.xml should be the same as the path attribute of the 
>>>> action
>>>
>>>
>>> element
>>>
>>>> in struts-config.xml.
>>>>
>>>> Quoting Adam Hardy <ah...@cyberspaceroad.com>:
>>>>
>>>>
>>>>
>>>>> Hmm., just realised the name of the form here is actually the 
>>>>> action mapping path. Should I be naming the forms in validation.xml 
>>>>> after the action mappings then rather than the form-beans from 
>>>>> struts-config?
>>>>>
>>>>>
>>>>> Adam Hardy wrote:
>>>>>
>>>>>
>>>>>> I set up the Validator to do automatic validation with normal 
>>>>>> action forms and it worked fine.
>>>>>>
>>>>>> Now I'm trying to incorporate dynaforms but I'm not having any 
>>>>>> luck. I'm
>>>
>>>
>>>>>> not getting  server-side validation carried out.
>>>>>>
>>>>>> I see from delving into the source code for struts and 
>>>>>> commons-validator
>>>
>>>
>>>>>> that the DynaValidatorAction form .validate() method is being 
>>>>>> called, but that the following line:
>>>>>>
>>>>>> Form form = resources.get(locale, formName);  (578)
>>>>>>
>>>>>> returns a null form and so the validation is skipped.
>>>>>>
>>>>>> I've obviously missed something out on the set-up and config, but 
>>>>>> what? Can anybody cast a light on this? Meanwhile I'll carry on 
>>>>>> digging....
>>>>>>
>>>>>> thanks
>>>>>> Adam
>>>>>>
>>>>>> (struts 1.1 & validator 1.0.2)

-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>



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


Re: DynaValidatorActionForm

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Sorry, panicing for a moment there :O - OK, I see the way the javascript 
tag works. It seems there no long validate function?

I think I have found the cause of my problem. In my dynaform definition, 
I set my id field type to Long - and when I enter a non-Long value in 
the form, the dynaform rejects it first and the dynaform long value 
remains null - therefore the validateLong() method will ignore it, 
because the validate long method can only validate a string. Is that so? 
Should I keep all my fields as strings in my form definition?


txs
Adam



Kris Schneider wrote:
> Okay, it sounded like you were just concerned with server-side validation. Try
> something like:
> 
> <head>
>   <html:javascript formName="/action/path" method="validateForm"/>
>   ...
> </head>
> 
> <body>
>   ...
>   <html:form action="/action/path" onsubmit="return validateForm(this);">
>   ...
> </body>
> 
> There are other best practices for organizing the "static" JavaScript, but try
> to get something working before worrying about that...
> 
> Quoting Adam Hardy <ah...@cyberspaceroad.com>:
> 
> 
>>In that case then there won't be any javascript validation set up 
>>automatically!
>>
>>Is that the only difference between DynaValidatorActionForm and 
>>DynaValidatorForm?
>>
>>I still haven't got this working. although I'm one step further.
>>
>>
>>
>>Kris Schneider wrote:
>>
>>>If you're using DynaValidatorActionForm, the name attribute of the form
>>
>>element
>>
>>>in validation.xml should be the same as the path attribute of the action
>>
>>element
>>
>>>in struts-config.xml.
>>>
>>>Quoting Adam Hardy <ah...@cyberspaceroad.com>:
>>>
>>>
>>>
>>>>Hmm., just realised the name of the form here is actually the action 
>>>>mapping path. Should I be naming the forms in validation.xml after the 
>>>>action mappings then rather than the form-beans from struts-config?
>>>>
>>>>
>>>>Adam Hardy wrote:
>>>>
>>>>
>>>>>I set up the Validator to do automatic validation with normal action 
>>>>>forms and it worked fine.
>>>>>
>>>>>Now I'm trying to incorporate dynaforms but I'm not having any luck. I'm
>>
>>>>>not getting  server-side validation carried out.
>>>>>
>>>>>I see from delving into the source code for struts and commons-validator
>>
>>>>>that the DynaValidatorAction form .validate() method is being called, 
>>>>>but that the following line:
>>>>>
>>>>>Form form = resources.get(locale, formName);  (578)
>>>>>
>>>>>returns a null form and so the validation is skipped.
>>>>>
>>>>>I've obviously missed something out on the set-up and config, but what? 
>>>>>Can anybody cast a light on this? Meanwhile I'll carry on digging....
>>>>>
>>>>>thanks
>>>>>Adam
>>>>>
>>>>>(struts 1.1 & validator 1.0.2)
> 
> 


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


Re: DynaValidatorActionForm

Posted by Kris Schneider <kr...@dotech.com>.
Okay, it sounded like you were just concerned with server-side validation. Try
something like:

<head>
  <html:javascript formName="/action/path" method="validateForm"/>
  ...
</head>

<body>
  ...
  <html:form action="/action/path" onsubmit="return validateForm(this);">
  ...
</body>

There are other best practices for organizing the "static" JavaScript, but try
to get something working before worrying about that...

Quoting Adam Hardy <ah...@cyberspaceroad.com>:

> In that case then there won't be any javascript validation set up 
> automatically!
> 
> Is that the only difference between DynaValidatorActionForm and 
> DynaValidatorForm?
> 
> I still haven't got this working. although I'm one step further.
> 
> 
> 
> Kris Schneider wrote:
> > If you're using DynaValidatorActionForm, the name attribute of the form
> element
> > in validation.xml should be the same as the path attribute of the action
> element
> > in struts-config.xml.
> > 
> > Quoting Adam Hardy <ah...@cyberspaceroad.com>:
> > 
> > 
> >>Hmm., just realised the name of the form here is actually the action 
> >>mapping path. Should I be naming the forms in validation.xml after the 
> >>action mappings then rather than the form-beans from struts-config?
> >>
> >>
> >>Adam Hardy wrote:
> >>
> >>>I set up the Validator to do automatic validation with normal action 
> >>>forms and it worked fine.
> >>>
> >>>Now I'm trying to incorporate dynaforms but I'm not having any luck. I'm
> 
> >>>not getting  server-side validation carried out.
> >>>
> >>>I see from delving into the source code for struts and commons-validator
> 
> >>>that the DynaValidatorAction form .validate() method is being called, 
> >>>but that the following line:
> >>>
> >>> Form form = resources.get(locale, formName);  (578)
> >>>
> >>>returns a null form and so the validation is skipped.
> >>>
> >>>I've obviously missed something out on the set-up and config, but what? 
> >>>Can anybody cast a light on this? Meanwhile I'll carry on digging....
> >>>
> >>>thanks
> >>>Adam
> >>>
> >>>(struts 1.1 & validator 1.0.2)

-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>

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


Re: DynaValidatorActionForm

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
In that case then there won't be any javascript validation set up 
automatically!

Is that the only difference between DynaValidatorActionForm and 
DynaValidatorForm?

I still haven't got this working. although I'm one step further.



Kris Schneider wrote:
> If you're using DynaValidatorActionForm, the name attribute of the form element
> in validation.xml should be the same as the path attribute of the action element
> in struts-config.xml.
> 
> Quoting Adam Hardy <ah...@cyberspaceroad.com>:
> 
> 
>>Hmm., just realised the name of the form here is actually the action 
>>mapping path. Should I be naming the forms in validation.xml after the 
>>action mappings then rather than the form-beans from struts-config?
>>
>>
>>Adam Hardy wrote:
>>
>>>I set up the Validator to do automatic validation with normal action 
>>>forms and it worked fine.
>>>
>>>Now I'm trying to incorporate dynaforms but I'm not having any luck. I'm 
>>>not getting  server-side validation carried out.
>>>
>>>I see from delving into the source code for struts and commons-validator 
>>>that the DynaValidatorAction form .validate() method is being called, 
>>>but that the following line:
>>>
>>> Form form = resources.get(locale, formName);  (578)
>>>
>>>returns a null form and so the validation is skipped.
>>>
>>>I've obviously missed something out on the set-up and config, but what? 
>>>Can anybody cast a light on this? Meanwhile I'll carry on digging....
>>>
>>>thanks
>>>Adam
>>>
>>>(struts 1.1 & validator 1.0.2)
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>>
>>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
> 
> 
> 


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


Re: DynaValidatorActionForm

Posted by Kris Schneider <kr...@dotech.com>.
If you're using DynaValidatorActionForm, the name attribute of the form element
in validation.xml should be the same as the path attribute of the action element
in struts-config.xml.

Quoting Adam Hardy <ah...@cyberspaceroad.com>:

> Hmm., just realised the name of the form here is actually the action 
> mapping path. Should I be naming the forms in validation.xml after the 
> action mappings then rather than the form-beans from struts-config?
> 
> 
> Adam Hardy wrote:
> > I set up the Validator to do automatic validation with normal action 
> > forms and it worked fine.
> > 
> > Now I'm trying to incorporate dynaforms but I'm not having any luck. I'm 
> > not getting  server-side validation carried out.
> > 
> > I see from delving into the source code for struts and commons-validator 
> > that the DynaValidatorAction form .validate() method is being called, 
> > but that the following line:
> > 
> >  Form form = resources.get(locale, formName);  (578)
> > 
> > returns a null form and so the validation is skipped.
> > 
> > I've obviously missed something out on the set-up and config, but what? 
> > Can anybody cast a light on this? Meanwhile I'll carry on digging....
> > 
> > thanks
> > Adam
> > 
> > (struts 1.1 & validator 1.0.2)
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> > 
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 


-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>

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


Re: DynaValidatorActionForm

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Hmm., just realised the name of the form here is actually the action 
mapping path. Should I be naming the forms in validation.xml after the 
action mappings then rather than the form-beans from struts-config?


Adam Hardy wrote:
> I set up the Validator to do automatic validation with normal action 
> forms and it worked fine.
> 
> Now I'm trying to incorporate dynaforms but I'm not having any luck. I'm 
> not getting  server-side validation carried out.
> 
> I see from delving into the source code for struts and commons-validator 
> that the DynaValidatorAction form .validate() method is being called, 
> but that the following line:
> 
>  Form form = resources.get(locale, formName);  (578)
> 
> returns a null form and so the validation is skipped.
> 
> I've obviously missed something out on the set-up and config, but what? 
> Can anybody cast a light on this? Meanwhile I'll carry on digging....
> 
> thanks
> Adam
> 
> (struts 1.1 & validator 1.0.2)
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 


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