Announcement Announcement Module
Collapse

Spring Modules forum decommissioned in favor of Spring Extensions

As the Spring Modules project has been replaced by the Spring Extensions (http://www.springsource.org/extensions) project, this forum has been decommissioned in favour of Spring Extensions one at:
http://forum.springsource.org/forumdisplay.php?f=44

Please see the Spring Extensions home page for a complete list of current projects in Java, .NET and ActionScript. You can also propose one if you want.

Cheers,
Costin Leau
SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
http://twitter.com/costinl
See more
See less
Spring Webflow 2 with Commons Validator and EventId Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Webflow 2 with Commons Validator and EventId

    I'm using commons validator in my spring webflow 2.

    I use FlowHandler and no Controller. From the references I have to make a class named <Modelname>Validator.

    I have overwritten the DefaultBeanValidator to get a validator with the specific name of my model. So the validator is successfully called by spring.

    I have defined all validations in the validation.xml. These validations are called successfully.

    The problem is that these validations are called every time. I have only found a way to suppress all binding and validation with the addition of bind="false" to the transition. But there are some events where I need the binding. For example I have a search of an element. This search is performed in the same form as other informations. So every submit will perform the whole validations.

    I need the eventid to define the kind of validation to perform. The only way to get this is to implement the method named after the state. There I have the context parameter. The method that calls the commons validator don't accept this parameter. It needs an object of errors.

    So my questions are:
    Is there a way to convert a context to an errors object or get one out of it?
    Or
    Is there a way to get the eventId in the validation(Object,Errors) method?
    Or
    Can I define an exclusion for special events direct to the validation of one field in the xml of commons validator?
    Or
    Is there a way of intercept the validation? So I can skip it if it isn't the right event or do only some validation.

    For now I have a hack where I define the method validate<name of state> where I get the eventId and put it in a variable the validate(object,errors) method can access. But there I have found some strange behaviour:
    I have to define the exact class in the method. The method validate<name of state>(object,context) is not called. Is this a bug?

    Thanks for reply

  • #2
    Spring webflow2 with commons validator

    Hi ,

    Could you please post the code for me. I am trying to write code with spring webflow2 and commons validator.

    Regards
    Kumar.T

    Comment


    • #3
      If you mean my hack here comes the code for it.

      Note: My model is named "formModel". I only except ignoring of the validation on the event with the id "next". So not all events can skip validation. For each controller AND state you have to implement the function with its name. (In this example validateShow is called for the state show of and the controller MyController. If you use different states AND different controllers you have to implement each combination. In my case I have the same state in 10 different controllers thanks to subflows.)

      I hope this helps!

      Code:
      @Component
      public class FormModelValidator extends DefaultBeanValidator {
      
           private String eventID;
      
           /*
           * This function sets the eventid global out of the context
           */
          private void preValid(ValidationContext context) {
              eventID = context.getUserEvent();
          }
          
          // FIXME Hack of the validation cause the eventId is not given
          public void validateShow(MyController obj, ValidationContext context) {
              preValid(context);
          }
      
          @Override
          public void validate(Object obj, Errors errors) {
              // is the object to validate an instance of my controller
              if (obj instanceof MyController) {
                  // is the event set to be ignored and the eventid is "next"
                  if (((MyController) obj).isIgnoreValidate() && eventID!=null && eventID.equalsIgnoreCase("next")) {
                      // do nothing so no validation is done
                      return;
                  }
              }
              // we call the validation in any other case
              super.validate(obj, errors);
      
          }

      Comment


      • #4
        Spring Webflow 2 with Commons Validator and EventId

        Hi MFochler,

        Many thanks for the reply. Could you please let me how you would configure validatorFactory in your application. I am not going to define my custom validator class in the application context xml. So , I am not able to get the work around of how we can go about declaring the validator factory.

        Regards
        Kumar.T

        Comment


        • #5
          I have devined it this way:

          Code:
              <bean id="validatorFactory" class="org.springmodules.validation.commons.DefaultValidatorFactory">
                  <property name="validationConfigLocations">
                      <list>
                          <value>/WEB-INF/validation.xml</value>
                          <value>/WEB-INF/validator-rules.xml</value>
                          <value>/WEB-INF/validator-rules-custom.xml</value>
                      </list>
                  </property>
              </bean>
              <bean id="formModelValidator" class="de.hshsoft.geso.gold.validation.FormModelValidator">
                  <property name="validatorFactory" ref="validatorFactory"/>
              </bean>

          Comment


          • #6
            Spring Webflow 2 with Commons Validator and EventId

            Hi MFochler,

            Thanks a lot for the help. It works now. I am able to integrate spring webflow2 with commons validator.

            Regards
            Kumar.T

            Comment


            • #7
              Spring Webflow 2 with Commons Validator (Client Side Validation)

              Hello MFochler,

              I have been trying to use the same commons validator for client side validation in a JSP. Have you done that before?. If yes ,Could you please let me know what all the jars that i need to plug in to make it work. I am currently struck up with class not found exception due to some jar file mismatch.

              Regards
              Kumar.T

              Comment


              • #8
                Spring Webflow 2 with Commons Validator and EventId

                Hi MFochler ,

                Again a doubt in Server side validation, I am trying to validate one more form along with the existing form. I did the same configuration for the new validator as the old one but when I am trying to validate , its throwing the error shown below. Could you please explain me how to configure validatorFactory for multiple form validation.

                java.lang.NullPointerException
                org.springmodules.validation.commons.AbstractBeanV alidator.getValidator(AbstractBeanValidator.java:9 4)
                org.springmodules.validation.commons.AbstractBeanV alidator.validate(AbstractBeanValidator.java:60)
                uk.gov.nhsbsa.dcss.manualcorrection.validator.Cust omerInfoBeanValidator.validateManualCorrect(Custom erInfoBeanValidator.java:27)
                sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
                sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
                sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
                java.lang.reflect.Method.invoke(Unknown Source)
                org.springframework.util.ReflectionUtils.invokeMet hod(ReflectionUtils.java:193)
                org.springframework.webflow.mvc.view.AbstractMvcVi ew.validate(AbstractMvcView.java:438)
                org.springframework.webflow.mvc.view.AbstractMvcVi ew.processUserEvent(AbstractMvcView.java:196)
                org.springframework.webflow.engine.ViewState.resum e(ViewState.java:199)
                org.springframework.webflow.engine.Flow.resume(Flo w.java:551)
                org.springframework.webflow.engine.impl.FlowExecut ionImpl.resume(FlowExecutionImpl.java:263)
                org.springframework.webflow.executor.FlowExecutorI mpl.resumeExecution(FlowExecutorImpl.java:153)
                org.springframework.webflow.mvc.servlet.FlowHandle rAdapter.handle(FlowHandlerAdapter.java:173)
                org.springframework.webflow.mvc.servlet.FlowContro ller.handleRequest(FlowController.java:172)
                org.springframework.web.servlet.mvc.SimpleControll erHandlerAdapter.handle(SimpleControllerHandlerAda pter.java:48)
                org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:875)
                org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:809)
                org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:571)
                org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:511)
                javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
                javax.servlet.http.HttpServlet.service(HttpServlet .java:717)

                Comment

                Working...
                X