commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Graham <grahamdavid1...@yahoo.com>
Subject Re: [commons-validator] Validator outside of Struts
Date Thu, 17 Feb 2005 14:19:44 GMT
The GenericValidator.isBlankOrNull(Object, Field) method does not exist.

http://jakarta.apache.org/commons/validator/apidocs/org/apache/commons/validator/GenericValidator.html#isBlankOrNull(java.lang.String)

You need to provide a wrapper method for GenericValidator.isBlankOrNull
and configure the wrapper in validator.xml.  Yes this is annoying and we
have a proposal to make this easier in future versions.  Struts provides
the FieldChecks.validateRequired() method as a wrapper with this
signature:

public static boolean validateRequired(Object bean,
    ValidatorAction va, Field field,
    ActionMessages errors, HttpServletRequest request)

BTW, your logging setup makes it very difficult to understand stack traces
with the timestamp cluttering every line.

David


--- Sébastien GALLET <sebastien@gallet.info> wrote:

> Humm, I dont know. ........ Because I've make a copy/paste from 
> validator examples.
> Now I use the GenericValidator
>       <validator name="required"
>                 
> classname="org.apache.commons.validator.GenericValidator"
>                  method="isBlankOrNull"
>                  
> methodParams="java.lang.Object,org.apache.commons.validator.Field"
>                  msg="errors.required"/>
> And I 've got another error
> 2005-02-17 01:07:12,132 INFO  [STDOUT] Exception when validating bean 
> info.gallet.titandb.person.Person
> 2005-02-17 01:07:12,132 INFO  [STDOUT] 
>
org.apache.commons.validator.GenericValidator.isBlankOrNull(java.lang.Object,
> 
> org.apach
> e.commons.validator.Field)
> 2005-02-17 01:07:12,132 INFO  [STDOUT] 
> org.apache.commons.validator.ValidatorException: 
> org.apache.commons.validator.GenericVa
> lidator.isBlankOrNull(java.lang.Object,
> org.apache.commons.validator.Field)
> 2005-02-17 01:07:12,133 INFO  [STDOUT]  at 
>
org.apache.commons.validator.ValidatorAction.loadValidationMethod(ValidatorAction.j
> ava:627)
> 2005-02-17 01:07:12,133 INFO  [STDOUT]  at 
>
org.apache.commons.validator.ValidatorAction.executeValidationMethod(ValidatorActio
> n.java:557)
> 2005-02-17 01:07:12,133 INFO  [STDOUT]  at 
> org.apache.commons.validator.Field.validateForRule(Field.java:811)
> 2005-02-17 01:07:12,133 INFO  [STDOUT]  at 
> org.apache.commons.validator.Field.validate(Field.java:890)
> 2005-02-17 01:07:12,133 INFO  [STDOUT]  at 
> org.apache.commons.validator.Form.validate(Form.java:174)
> 2005-02-17 01:07:12,133 INFO  [STDOUT]  at 
> org.apache.commons.validator.Validator.validate(Validator.java:367)
> 2005-02-17 01:07:12,133 INFO  [STDOUT]  at 
> info.gallet.marmot.ValidatorTest.validate(ValidatorTest.java:124)
> 2005-02-17 01:07:12,133 INFO  [STDOUT]  at 
> info.gallet.titandbtest.Test2.processRequest(Test2.java:141)
> 2005-02-17 01:07:12,133 INFO  [STDOUT]  at 
> info.gallet.titandbtest.Test2.doGet(Test2.java:195)
> 2005-02-17 01:07:12,133 INFO  [STDOUT]  at 
> javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
> 2005-02-17 01:07:12,133 INFO  [STDOUT]  at 
> javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
> 2005-02-17 01:07:12,133 INFO  [STDOUT]  at 
>
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterC
> hain.java:237)
> 2005-02-17 01:07:12,133 INFO  [STDOUT]  at 
>
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.jav
> a:157)
> 2005-02-17 01:07:12,133 INFO  [STDOUT]  at 
>
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
> 2005-02-17 01:07:12,133 INFO  [STDOUT]  at 
>
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterC
> hain.java:186)
> 2005-02-17 01:07:12,134 INFO  [STDOUT]  at 
>
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.jav
> a:157)
> 2005-02-17 01:07:12,134 INFO  [STDOUT]  at 
>
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
> 2005-02-17 01:07:12,134 INFO  [STDOUT]  at 
>
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:
> 104)
> 2005-02-17 01:07:12,134 INFO  [STDOUT]  at 
>
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
> 2005-02-17 01:07:12,134 INFO  [STDOUT]  at 
>
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.j
> ava:198)
> 2005-02-17 01:07:12,134 INFO  [STDOUT]  at 
>
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
> 2005-02-17 01:07:12,134 INFO  [STDOUT]  at 
>
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:
> :
> 104)
> 2005-02-17 01:07:12,134 INFO  [STDOUT]  at 
>
org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java
> :66)
> 2005-02-17 01:07:12,134 INFO  [STDOUT]  at 
>
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:
> 102)
> 2005-02-17 01:07:12,134 INFO  [STDOUT]  at 
>
org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationVa
> lve.java:153)
> 2005-02-17 01:07:12,134 INFO  [STDOUT]  at 
>
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:
> 102)
> 2005-02-17 01:07:12,134 INFO  [STDOUT]  at 
>
org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:54)
> 2005-02-17 01:07:12,134 INFO  [STDOUT]  at 
>
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:
> 102)
> 2005-02-17 01:07:12,134 INFO  [STDOUT]  at 
>
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
> 2005-02-17 01:07:12,134 INFO  [STDOUT]  at 
>
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
> 2005-02-17 01:07:12,134 INFO  [STDOUT]  at 
>
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:
> 104)
> 2005-02-17 01:07:12,135 INFO  [STDOUT]  at 
>
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
> 2005-02-17 01:07:12,135 INFO  [STDOUT]  at 
>
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:
> 102)
> 2005-02-17 01:07:12,135 INFO  [STDOUT]  at 
>
org.apache.catalina.authenticator.SingleSignOn.invoke(SingleSignOn.java:417)
> 2005-02-17 01:07:12,135 INFO  [STDOUT]  at 
>
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:
> 102)
> 2005-02-17 01:07:12,135 INFO  [STDOUT]  at 
>
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:535)
> 2005-02-17 01:07:12,135 INFO  [STDOUT]  at 
>
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:
> 102)
> 2005-02-17 01:07:12,135 INFO  [STDOUT]  at 
>
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
> 2005-02-17 01:07:12,135 INFO  [STDOUT]  at 
>
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
> 2005-02-17 01:07:12,135 INFO  [STDOUT]  at 
>
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:
> 104)
> 2005-02-17 01:07:12,135 INFO  [STDOUT]  at 
>
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
> 2005-02-17 01:07:12,135 INFO  [STDOUT]  at 
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
> 2005-02-17 01:07:12,135 INFO  [STDOUT]  at 
> org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
> 2005-02-17 01:07:12,135 INFO  [STDOUT]  at 
>
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
> 2005-02-17 01:07:12,135 INFO  [STDOUT]  at 
>
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(H
> ttp11Protocol.java:705)
> 2005-02-17 01:07:12,135 INFO  [STDOUT]  at 
>
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
> 2005-02-17 01:07:12,135 INFO  [STDOUT]  at 
>
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
> 2005-02-17 01:07:12,136 INFO  [STDOUT]  at 
> java.lang.Thread.run(Thread.java:534)
> 
> 
> David Graham a écrit :
> 
> >Why are you using org.apache.commons.validator.TestValidator?  What is
> the
> >full stack trace for the exception?
> >
> >David
> >
> >
> >--- Sébastien GALLET <sebastien@gallet.info> wrote:
> >
> >  
> >
> >>Hello,
> >>I try to use commons validator oustide of struts.
> >>I've create a class ValidatorTest with the 2 main following methods :
> >>
> >>    /** The default construtor
> >>    *
> >>    */
> >>    public ValidatorTest() {
> >>
> >>        InputStream in = null;
> >>        System.out.println("Try to init validator");
> >>       
> >>        try {
> >>            in =
> >>this.getClass().getResourceAsStream("validatortest.xml");
> >>            resources = new ValidatorResources(in);
> >>        } catch (Exception e) {
> >>            System.out.println("Exception when initialising
> validator");
> >>            System.out.println(e.getMessage());
> >>            e.printStackTrace(System.out);
> >>        } finally {
> >>            // Make sure we close the input stream.
> >>            if (in != null) {
> >>                try { in.close();} catch (Exception f) {};
> >>            }
> >>        }
> >>    }
> >>   
> >>    /** Validate the POJO.
> >>    *
> >>    */
> >>    public boolean validate(Object obj) {
> >>        boolean result = true;
> >>        System.out.println("Try to validate bean 
> >>"+obj.getClass().getName());
> >>        try {
> >>            Validator _validator = new Validator(resources, 
> >>obj.getClass().getName());
> >>            _validator.setParameter(Validator.BEAN_PARAM, obj);
> >>//            _validator.setOnlyReturnErrors(true);
> >>           
> >>            results = null;         
> >>            results = _validator.validate();
> >>        } catch (Exception e) {
> >>            result=false;
> 
=== message truncated ===



		
__________________________________ 
Do you Yahoo!? 
The all-new My Yahoo! - Get yours free! 
http://my.yahoo.com 
 


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


Mime
View raw message