You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Frank Burns <fr...@the-hub.demon.co.uk> on 2004/03/12 03:01:59 UTC

Strange behaviour?

I have a validate() method in my ActionForm class that includes some cleanup
(removes redundant whitespace) of some of the ActionForm bean's properties.
The related Action has validate="true" set in struts-config. So validate()
should always be called.

The Action class then uses the ActionsForm's getters to read these
properties and saves them.

However, the saved properties have only been cleaned when errors are found
by the validate() method.

Why?

The validate() method is ALWAYS called and executes the cleanup methods on
the properties whether validate() discover errors or not, right?

Specifically, in the code below, the answer1, answer2, etc., are only
"cleaned" if there is an error found in the email address.

/*** code snippet ***/

 public ActionErrors validate(
  ActionMapping mapping,
  HttpServletRequest request) {

  /* clean redundant whitespace from answers properties */
  answer1 = cleanWhitespace(answer1);
  answer2 = cleanWhitespace(answer2);
  answer3 = cleanWhitespace(answer3);

  ActionErrors errors = new ActionErrors();

  /*** validate email address ***/

  /* check is email address is not empty */
  if ((emailAddr == null) || (emailAddr.length() < 1)){
   errors.add("emailaddressempty",
    new ActionError("errors.required.emailaddress"));
  }

...

    return errors;
}




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


Re: Strange behaviour?

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
The question is, where does your action forward to in the "valid" scenario
after it has "saved" your properties? Are you forwarding to another action
which is re-popoulating the form from the request?

How about putting the cleanWhitespace() in your setters, rather than the
validate() method:

   public void setAnswer1(String answer1) {
        this.answer1 = cleanWhitespace(answer1);
   }

Niall

----- Original Message ----- 
From: "Frank Burns" <fr...@the-hub.demon.co.uk>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Friday, March 12, 2004 2:01 AM
Subject: Strange behaviour?


> I have a validate() method in my ActionForm class that includes some
cleanup
> (removes redundant whitespace) of some of the ActionForm bean's
properties.
> The related Action has validate="true" set in struts-config. So validate()
> should always be called.
>
> The Action class then uses the ActionsForm's getters to read these
> properties and saves them.
>
> However, the saved properties have only been cleaned when errors are found
> by the validate() method.
>
> Why?
>
> The validate() method is ALWAYS called and executes the cleanup methods on
> the properties whether validate() discover errors or not, right?
>
> Specifically, in the code below, the answer1, answer2, etc., are only
> "cleaned" if there is an error found in the email address.
>
> /*** code snippet ***/
>
>  public ActionErrors validate(
>   ActionMapping mapping,
>   HttpServletRequest request) {
>
>   /* clean redundant whitespace from answers properties */
>   answer1 = cleanWhitespace(answer1);
>   answer2 = cleanWhitespace(answer2);
>   answer3 = cleanWhitespace(answer3);
>
>   ActionErrors errors = new ActionErrors();
>
>   /*** validate email address ***/
>
>   /* check is email address is not empty */
>   if ((emailAddr == null) || (emailAddr.length() < 1)){
>    errors.add("emailaddressempty",
>     new ActionError("errors.required.emailaddress"));
>   }
>
> ...
>
>     return errors;
> }
>
>
>
>
> ---------------------------------------------------------------------
> 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: Strange behaviour?

Posted by Hubert Rabago <ja...@yahoo.com>.
You can put log statements in your form bean's setter methods to verify that
they are being called.  My guess is that your configuration is causing struts
to reinitialize the form somehow and that resets the form values.  All I can
do is guess, though, since I have no idea how your mappings are configured.

Hubert

--- Frank Burns <fr...@the-hub.demon.co.uk> wrote:
> I have a validate() method in my ActionForm class that includes some
> cleanup
> (removes redundant whitespace) of some of the ActionForm bean's properties.
> The related Action has validate="true" set in struts-config. So validate()
> should always be called.
> 
> The Action class then uses the ActionsForm's getters to read these
> properties and saves them.
> 
> However, the saved properties have only been cleaned when errors are found
> by the validate() method.
> 
> Why?
> 
> The validate() method is ALWAYS called and executes the cleanup methods on
> the properties whether validate() discover errors or not, right?
> 
> Specifically, in the code below, the answer1, answer2, etc., are only
> "cleaned" if there is an error found in the email address.
> 
> /*** code snippet ***/
> 
>  public ActionErrors validate(
>   ActionMapping mapping,
>   HttpServletRequest request) {
> 
>   /* clean redundant whitespace from answers properties */
>   answer1 = cleanWhitespace(answer1);
>   answer2 = cleanWhitespace(answer2);
>   answer3 = cleanWhitespace(answer3);
> 
>   ActionErrors errors = new ActionErrors();
> 
>   /*** validate email address ***/
> 
>   /* check is email address is not empty */
>   if ((emailAddr == null) || (emailAddr.length() < 1)){
>    errors.add("emailaddressempty",
>     new ActionError("errors.required.emailaddress"));
>   }
> 
> ...
> 
>     return errors;
> }
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you�re looking for faster
http://search.yahoo.com

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