Re: JXPath Validator

2004-03-03 Thread Niall Pemberton
Sounds good to me.

I don't know if the validator guys considered JXPath, but why don't you
submit an enhacement request using bugzilla to commons with your JXPath
validator attached (if you include JUnit tests you'll impress them even
more).

For some reason the 'validwhen' validator is part of struts (rather than
commons validator) - I don't know why this is. From the look of it, it could
have been implemented in commons with a method in struts to call it. From
what I can see the only reason validwhen needs the HttpServletRequest is so
that it can get error messages. Presumably to process error messages in the
same way in a struts environment, yours would need to do a similar thing -
but that could be handled with a validate method in struts which calls your
commons JXPath validator.

Niall

- Original Message - 
From: "Michael Nascimento Santos" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Wednesday, March 03, 2004 3:42 PM
Subject: JXPath Validator


> Hi guys,
>
> I am just wondering: you guys have developed validwhen so we could have a
> more powerful validator, right? But, while using just commons-validator in
a
> GUI (non-web) project, I noticed I could implement a very powerful
validator
> using
> JXPath.
>
> Here is the code for the static method:
>
>public static boolean validateJXPath(Object bean, Field field) {
>   final JXPathContext ctx = JXPathContext.newContext(bean);
>
>   return
> !Boolean.FALSE.equals(ctx.getValue(field.getVarValue("jxpath")));
>}
>
> Notice it's just a simple validator with no dependencies on
> HttpServletRequest or ActionErrors. I don't know that much about
validwhen,
> but from what I've seen, XPath expressions can do everything validwhen
> expressions can and even more.
>
> Am I missing something? Is there any reason why a JXPath-based validator
as
> the above wouldn't be suitable for Struts?
>
> Regards,
> Michael Nascimento Santos
> JSR 207 Expert Group Member
> http://today.java.net/pub/au/80
> Sun Certified Programmer for the Java 2 Platform 1.4
> Sun Certified Web Component Developer for J2EE
> Moderador SouJava - http://www.soujava.org.br
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



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



JXPath Validator

2004-03-03 Thread Michael Nascimento Santos
Hi guys,

I am just wondering: you guys have developed validwhen so we could have a
more powerful validator, right? But, while using just commons-validator in a
GUI (non-web) project, I noticed I could implement a very powerful validator
using
JXPath.

Here is the code for the static method:

   public static boolean validateJXPath(Object bean, Field field) {
  final JXPathContext ctx = JXPathContext.newContext(bean);

  return
!Boolean.FALSE.equals(ctx.getValue(field.getVarValue("jxpath")));
   }

Notice it's just a simple validator with no dependencies on
HttpServletRequest or ActionErrors. I don't know that much about validwhen,
but from what I've seen, XPath expressions can do everything validwhen
expressions can and even more.

Am I missing something? Is there any reason why a JXPath-based validator as
the above wouldn't be suitable for Struts?

Regards,
Michael Nascimento Santos
JSR 207 Expert Group Member
http://today.java.net/pub/au/80
Sun Certified Programmer for the Java 2 Platform 1.4
Sun Certified Web Component Developer for J2EE
Moderador SouJava - http://www.soujava.org.br

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