You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Michael Nascimento Santos <mi...@hotmail.com> on 2004/03/02 23:44:53 UTC

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 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 expression 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: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org