Announcement Announcement Module
Collapse
No announcement yet.
Jakarta Commons Validator integration? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Jakarta Commons Validator integration?

    Has anyone worked on integrating Jakarta Commons Validator with Spring? It's the Validator framework used by Struts. If you have can you share your code?

  • #2
    It's actually already integrated. In fact, there is even an xdoclet module to generate the XML. It's in the sandbox currently. There are some issues waiting to be resolved before it will get integrated into project. Some issues may never be resolved, though.

    Good news is that it works fine.

    Comment


    • #3
      Daniel Miller added Support, see:
      http://sourceforge.net/mailarchive/f...forum_id=28401
      and Matt Raible got a some further explanations in his Spring live book see:
      http://www.jroller.com/page/raible
      or
      http://www.sourcebeat.com/TitleAction.do?id=7
      HtH

      Comment


      • #4
        Here's an updated how to:

        http://www.jroller.com/page/raible/2...or_with_spring

        If you're going to use this, you might want to be aware of this issue:

        http://opensource.atlassian.com/proj...browse/SPR-238

        Matt

        Comment


        • #5
          Commons Validator for business tier?

          I am trying to use the Commons Validator support, except I am trying to use it for business tier validations. I followed the directions from Matt Raible's blog (except for step 4 since that didn't apply). I have code in a business object to invoke validation on an object:

          Code:
                  BindException errors = new BindException(cktId, "CktId"); 
                  beanValidator.validate(cktId, errors);
                  if(errors.hasErrors())
                  {
                      throw new RuntimeException(errors);
                  }
          This business object was given beanValidator in my applicationContext.xml.

          And my validations.xml looks like this:
          Code:
          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN" "http&#58;//jakarta.apache.org/commons/dtds/validator_1_0.dtd">
          <form-validation>
           <formset>
            <form name="CktId">
              <field
                property="issue"
                depends="required,maxlength">
                <arg0 key="issue.label"/>
                <arg1 name="maxlength" key="$&#123;var&#58;maxlength&#125;" resource="false"/>
                <var><var-name>maxlength</var-name><var-value>5</var-value></var>
              </field>
            </form>
           </formset>
          </form-validation>
          I've tried violating both required and maxlength validations, but I get back no errors in both cases. The RuntimeException never gets thrown. It appears to be at least recognizing the validation.xml file, because if I mislabel the form name tag, I get an error in my logs.

          Note that I don't have any message resources configured (not sure how to do that yet), so the message keys ("issue.label") will not resolve to anything, but could that cause the problem?

          Comment


          • #6
            Found my problem... I changed "CktId" to "cktId" in both parts of the code I posted. I had tried that before, but the problem then was that I was not using validation-rules.xml that is specific for Spring (I was using the original Commons version of it).

            Comment


            • #7
              are there any news about moving this out of the sandbox into regular release?
              it is also mentioned in the confluence, see http://opensource.atlassian.com/conf...wComments=true

              Comment


              • #8
                Anyone knows if Daniel's integration supports showing all form errors in one javascript popup?

                tnx,

                jan

                Comment


                • #9
                  In terms of alternative validation approaches, we're using Spring's standard Validator interface along with fValidate, which is very feature-rich. Take a look at the demo if you're after a quality JavaScript-based solution: http://www.peterbailey.net/fValidate/demo/

                  Comment


                  • #10
                    Originally posted by olorin
                    Anyone knows if Daniel's integration supports showing all form errors in one javascript popup?
                    Yes, it does. You can see a demo at http://demo.raibledesigns.com/appfus...ng/signup.html. Just hit the signup button w/o entering in any of the required fields.

                    Matt

                    Comment


                    • #11
                      Originally posted by mraible
                      Doh! The period got included in the link above. Here's one that actually works:

                      http://demo.raibledesigns.com/appfus...ng/signup.html

                      Comment


                      • #12
                        Sorry for being unclear in my problem description.
                        Error messages for fields violating the same rule (like required) are indeed grouped.
                        But if fields violate different rules (like required and float) i.e. they are handled by different functions in the javascript, error messages show up in different popups.

                        BTW: I see accented characters do not show up well in french in appfuse.
                        maybe setting charset to iso-8859-1 can solve this.
                        (and take care with i18n and commons validator: it will not validate localized float formats)

                        rgds,


                        jan[/url]

                        Comment


                        • #13
                          Spring1.1.3 and spring-sandbox.jar

                          Hi;

                          I am using Spring1.1.3 and then downlowed the spring-sandbox.jar, configured the common validators following matt's SpringLive. But, when even my first page could not be displayed. It threw an exception as follows. Any idea what went wrong? Thanks.

                          An Error has occurred in this application.
                          javax.servlet.ServletException: Servlet.init() for servlet action threw exception
                          at org.apache.catalina.core.StandardWrapper.loadServl et(StandardWrapper.java:1071)
                          at org.apache.catalina.core.StandardWrapper.allocate( StandardWrapper.java:687)
                          at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:144)
                          at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:104)
                          at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:520)
                          at org.apache.catalina.core.StandardContextValve.invo keInternal(StandardContextValve.java:198)
                          at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:152)
                          at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:104)
                          at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:520)
                          at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:137)
                          at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:104)
                          at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:118)
                          at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:102)
                          at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:520)
                          at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
                          at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:104)
                          at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:520)
                          at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:929)
                          at org.apache.coyote.tomcat5.CoyoteAdapter.service(Co yoteAdapter.java:160)
                          at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:799)
                          at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.jav a:705)
                          at org.apache.tomcat.util.net.TcpWorkerThread.runIt(P oolTcpEndpoint.java:577)
                          at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:683)
                          at java.lang.Thread.run(Thread.java:534)

                          Comment


                          • #14
                            Hmmm. The stack trace really doesn't say anything. Can you look in your Tomcat log files and see if you can find a more precise error message? Are you using this with Equinox or in your own application?

                            Comment


                            • #15
                              I checked the tomcat log, it has the following besides those messages:

                              ----- Root Cause -----
                              java.lang.NoSuchMethodError: org.springframework.util.ClassUtils.forName(Ljava/lang/StringLjava/lang/Class;
                              at org.springframework.beans.factory.config.CustomEdi torConfigurer.postProcessBeanFactory(CustomEditorC onfigurer.java:93)
                              at org.springframework.context.support.AbstractApplic ationContext.invokeBeanFactoryPostProcessors(Abstr actApplicationContext.java:361)
                              at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:299)
                              at org.springframework.web.context.support.AbstractRe freshableWebApplicationContext.refresh(AbstractRef reshableWebApplicationContext.java:131)
                              at org.springframework.web.servlet.FrameworkServlet.c reateWebApplicationContext(FrameworkServlet.java:2 83)
                              at org.springframework.web.servlet.FrameworkServlet.i nitWebApplicationContext(FrameworkServlet.java:230 )
                              at org.springframework.web.servlet.FrameworkServlet.i nitServletBean(FrameworkServlet.java:199)
                              at org.springframework.web.servlet.HttpServletBean.in it(HttpServletBean.java:103)
                              at javax.servlet.GenericServlet.init(GenericServlet.j ava:211)
                              at org.apache.catalina.core.StandardWrapper.loadServl et(StandardWrapper.java:1029)

                              =============================================
                              Is there some mismatch or environment setup problem? I am developing a separate application, but used SpringLive's myuser as the basis (I upgraded the spring.jar to 1.1.3 since when I tried to configure exposeMacros... for velocity resolver, it complained something (and seems it was not a property in 1.1.1 version I used...). Thanks.

                              Comment

                              Working...
                              X