Re: Pluggable Validator question

2006-04-25 Thread kkumar
Everyone,

I found the problem in my code. I was using ActionErrors in my custom
validation method instead of ActionMessages. I found again that the
mistakes done on obvious pieces are difficult to track down.

Do I need to close this discussion?

Thanks all,
Kiran


-
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]



Re: Pluggable Validator question

2006-04-25 Thread kkumar
Hi Niall,

Up on further search, I found questions like mine in various forums. The
problem is I guess I am not adding the errors in the validation method
correctly. Also, the I added the following line in my method.

---
errors = new ActionErrors();


I did this because I had a null pointer exception (errors was null).
So, I think the problem with my code is errors (object of ActionErrors) in
my validatation method is "null". How do I correct this error?

Thanks,
Kiran




-
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]



Re: Pluggable Validator question

2006-04-25 Thread kkumar
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" 
  To 
   "Struts Users Mailing List" 
 04/24/2006 08:15  
 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

>  name="pwdForm"
>  type="actions.PWDAction"
>  scope="request"
>  validate="true"
>  input="/password.jsp"
>  forward="/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 st

Re: Pluggable Validator question

2006-04-24 Thread Niall Pemberton
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

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

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



Re: Pluggable Validator question

2006-04-24 Thread kkumar

Dave,

Here's my method that does the validation:

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

Here's the snippet from validations.xml.

  
  
  
  
  
  secondProperty
  pwd2
  

  


Here's the snippet from validation-rules.xml





Here's password.jsp.

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>


  

  
  
pwd # 

pwd # 

Submit
  
  

  




My PWDAction.java doesn't have much. But, here it is.

public class PWDAction extends Action {
  public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {

return mapping.findForward("success");
  }
}

Advanced thanks for your time,
Kiran

















   
 Dave Newton   
 <[EMAIL PROTECTED] 
 com>   To 
   Struts Users Mailing List   
 04/24/2006 04:43  
 PM cc 
       
       Subject 
 Please respond to Re: Pluggable Validator question
   "Struts Users   
   Mailing List"   
 <[EMAIL PROTECTED] 
  he.org>  
   
   




[EMAIL PROTECTED] wrote:
> What am I doing wrong?
>

Don't know.

Unfortunately showing us an action mapping isn't enough to help, since
there's configuration, code, etc. involved.

Dave



-
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]



Re: Pluggable Validator question

2006-04-24 Thread Dave Newton
[EMAIL PROTECTED] wrote:
> What am I doing wrong?
>   

Don't know.

Unfortunately showing us an action mapping isn't enough to help, since
there's configuration, code, etc. involved.

Dave



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