You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ben Anderson <be...@benanderson.us> on 2004/10/06 21:57:06 UTC

validateTwoFields

Hi all,
I'm trying to use this custom validate method.  I got the instructions from Matt
Raible's site (thanks Matt ;-)):
http://www.raibledesigns.com/page/rd/20030226

I remember this used to work, but now it's not.  I'm using Struts 1.2.4 and
commons-validator 1.1.3.  I've been playing with it a little and found that the
problem is that the incoming errors parameter is null.  I know something
concerning ActionErrors has gone into place with the recent struts releases
(i.e. "don't use ActionErrors", I think?)  Anyways, I'd like to write a few
other custom validation methods, which is really why I'm planning on using
Struts for my current project.  Has anyone figured out this problem or know of
any other documentation.

  public static boolean validateTwoFields(Object bean, ValidatorAction va,
                                        Field field, ActionErrors errors,
                                        HttpServletRequest request) {
    String value =
        ValidatorUtils.getValueAsString(bean, field.getProperty());
    String sProperty2 = field.getVarValue("secondProperty");
    String value2 = ValidatorUtils.getValueAsString(bean, sProperty2);

    LOG.debug("errors: "+errors);  // this is null

    if (!GenericValidator.isBlankOrNull(value)) {
        try {
            if (!value.equals(value2)) {
                errors.add(field.getKey(),
                           Resources.getActionError(request, va, field));

                return false;
            }
        } catch (Exception e) {
            errors.add(field.getKey(),
                       Resources.getActionError(request, va, field));

            return false;
        }
    }

Thanks,
Ben

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


Re: validateTwoFields

Posted by Matt Bathje <mp...@ntsource.com>.
Ben - long story short for custom validators (and your example here 
specfically) is to change ActionErrors here to ActionMessages, and then 
in the validator-rules.xml definition, replace the ActionErrors part of 
methodParams with ActionMessages. You will probably need to replace the
Resources.getActionError(request, va, field) with 
Resources.getActionMessage(request, va, field)


Matt



Hubert Rabago wrote:

> Hi Ben,
> 
> For more info about the ActionError/ActionErrors situation, see
> http://wiki.apache.org/struts/StrutsDeprecatedActionErrors
> 
> Hubert
> 
> On Wed,  6 Oct 2004 12:57:06 -0700, Ben Anderson
> <be...@benanderson.us> wrote:
> 
>>Hi all,
>>I'm trying to use this custom validate method.  I got the instructions from Matt
>>Raible's site (thanks Matt ;-)):
>>http://www.raibledesigns.com/page/rd/20030226
>>
>>I remember this used to work, but now it's not.  I'm using Struts 1.2.4 and
>>commons-validator 1.1.3.  I've been playing with it a little and found that the
>>problem is that the incoming errors parameter is null.  I know something
>>concerning ActionErrors has gone into place with the recent struts releases
>>(i.e. "don't use ActionErrors", I think?)  Anyways, I'd like to write a few
>>other custom validation methods, which is really why I'm planning on using
>>Struts for my current project.  Has anyone figured out this problem or know of
>>any other documentation.
>>
>> public static boolean validateTwoFields(Object bean, ValidatorAction va,
>>                                       Field field, ActionErrors errors,
>>                                       HttpServletRequest request) {
>>   String value =
>>       ValidatorUtils.getValueAsString(bean, field.getProperty());
>>   String sProperty2 = field.getVarValue("secondProperty");
>>   String value2 = ValidatorUtils.getValueAsString(bean, sProperty2);
>>
>>   LOG.debug("errors: "+errors);  // this is null
>>
>>   if (!GenericValidator.isBlankOrNull(value)) {
>>       try {
>>           if (!value.equals(value2)) {
>>               errors.add(field.getKey(),
>>                          Resources.getActionError(request, va, field));
>>
>>               return false;
>>           }
>>       } catch (Exception e) {
>>           errors.add(field.getKey(),
>>                      Resources.getActionError(request, va, field));
>>
>>           return false;
>>       }
>>   }
>>
>>Thanks,
>>Ben
>>
>>---------------------------------------------------------------------
>>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


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


Re: validateTwoFields

Posted by Hubert Rabago <hr...@gmail.com>.
Hi Ben,

For more info about the ActionError/ActionErrors situation, see
http://wiki.apache.org/struts/StrutsDeprecatedActionErrors

Hubert

On Wed,  6 Oct 2004 12:57:06 -0700, Ben Anderson
<be...@benanderson.us> wrote:
> Hi all,
> I'm trying to use this custom validate method.  I got the instructions from Matt
> Raible's site (thanks Matt ;-)):
> http://www.raibledesigns.com/page/rd/20030226
> 
> I remember this used to work, but now it's not.  I'm using Struts 1.2.4 and
> commons-validator 1.1.3.  I've been playing with it a little and found that the
> problem is that the incoming errors parameter is null.  I know something
> concerning ActionErrors has gone into place with the recent struts releases
> (i.e. "don't use ActionErrors", I think?)  Anyways, I'd like to write a few
> other custom validation methods, which is really why I'm planning on using
> Struts for my current project.  Has anyone figured out this problem or know of
> any other documentation.
> 
>  public static boolean validateTwoFields(Object bean, ValidatorAction va,
>                                        Field field, ActionErrors errors,
>                                        HttpServletRequest request) {
>    String value =
>        ValidatorUtils.getValueAsString(bean, field.getProperty());
>    String sProperty2 = field.getVarValue("secondProperty");
>    String value2 = ValidatorUtils.getValueAsString(bean, sProperty2);
> 
>    LOG.debug("errors: "+errors);  // this is null
> 
>    if (!GenericValidator.isBlankOrNull(value)) {
>        try {
>            if (!value.equals(value2)) {
>                errors.add(field.getKey(),
>                           Resources.getActionError(request, va, field));
> 
>                return false;
>            }
>        } catch (Exception e) {
>            errors.add(field.getKey(),
>                       Resources.getActionError(request, va, field));
> 
>            return false;
>        }
>    }
> 
> Thanks,
> Ben
> 
> ---------------------------------------------------------------------
> 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