Niall,

If you see my earlier reply to my question, I included the source code of
my validateTwoField(..) method. I include it here again for your perusal. I
do instantiate the ActionErrors object and add an ActionMessage as you see.


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);

            if (!GenericValidator.isBlankOrNull(value)) {
               try {
                    if (!value.equals(value2)) {

                         errors.add(field.getKey(), new ActionMessage(
"errors.twofields", value, value2));

                         return false;
                    }
               } catch (Exception e) {
                        errors.add(field.getKey(), new ActionMessage(
"errors.twofields", value, value2));
                        return false;
               }
            }

            return true;
      }

But, when I debugged, I saw somewhere in the Struts code that the
ActionErrors is still empty and may be that's the reason it's not going
back to the input page. I searched a lot on the internet and found examples
on versions of struts which are now deprecated. So, in replacing that code,
I could have gone wrong somewhere in adding ActionMessages to the
ActionErrors.. Can you please tell me if errors.add(field.getKey(), new
ActionMessage("errors.twofields", value, value2)); is the correct way of
doing it?


Thanks,
Kiran



                                                                           
             "Niall Pemberton"                                             
             <niall.pemberton@                                             
             gmail.com>                                                 To 
                                       "Struts Users Mailing List"         
             04/24/2006 08:15          <user@struts.apache.org>            
             PM                                                         cc 
                                                                           
                                                                   Subject 
             Please respond to         Re: Pluggable Validator question    
               "Struts Users                                               
               Mailing List"                                               
             <[EMAIL PROTECTED]                                             
                  he.org>                                                  
                                                                           
                                                                           




On 4/24/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Hello All,
>
> I am trying to use the TwoField pluggable Validator example from the
> struts's site. I replaced the deprecated method calls in
> validateTwoFields(..). For some reason, when I run my application, it
> doesn't validate the input fields. Instead it directly takes me to the
> success page after I hit submit. I tried debugging the
> validateTwoFields(..) and found that it's returning "false" when the
input
> fields did not match. But still the control is forwarding to the success
> page. Here's my action mapping.

Returning "false" from a validator doesn't stop struts from continuing
- its adding a message(s) to the ActionErrors returned by the
ActionForm's validate method. If you look at the Struts FieldChecks
class you will see that all the configured methods do that. So is your
validateTwoFields(...) method doing it?

Niall

>            <action     path="/pwdAction"
>                  name="pwdForm"
>                  type="actions.PWDAction"
>                  scope="request"
>                  validate="true"
>                  input="/password.jsp"
>                  forward="/success.jsp">
>                  <forward name="success" path="/success.jsp"/>
>
>
> What am I doing wrong?
>
> Thanks,
> Kiran

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-----------------------------------------
The information contained in this message is intended only for the
personal and confidential use of the recipient(s) named above. If
the reader of this message is not the intended recipient or an
agent responsible for delivering it to the intended recipient, you
are hereby notified that you have received this document in error
and that any review, dissemination, distribution, or copying of
this message is strictly prohibited. If you have received this
communication in error, please notify us immediately, and delete
the original message.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to