Announcement Announcement Module

Spring Modules forum decommissioned in favor of Spring Extensions

As the Spring Modules project has been replaced by the Spring Extensions ( project, this forum has been decommissioned in favour of Spring Extensions one at:

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.

Costin Leau
SpringSource - Spring Training, Consulting, and Support - "From the Source"
See more
See less
Spring Webflow 2 with Commons Validator and EventId Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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?
    Is there a way to get the eventId in the validation(Object,Errors) method?
    Can I define an exclusion for special events direct to the validation of one field in the xml of commons validator?
    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.



    • #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!

      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) {
          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
              // we call the validation in any other case
              super.validate(obj, errors);


      • #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.



        • #5
          I have devined it this way:

              <bean id="validatorFactory" class="org.springmodules.validation.commons.DefaultValidatorFactory">
                  <property name="validationConfigLocations">
              <bean id="formModelValidator" class="">
                  <property name="validatorFactory" ref="validatorFactory"/>


          • #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.



            • #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.



              • #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.

                org.springmodules.validation.commons.AbstractBeanV alidator.getValidator( 4)
                org.springmodules.validation.commons.AbstractBeanV alidator.validate(
                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(
                org.springframework.webflow.mvc.view.AbstractMvcVi ew.validate(
                org.springframework.webflow.mvc.view.AbstractMvcVi ew.processUserEvent(
                org.springframework.webflow.engine.ViewState.resum e(
                org.springframework.webflow.engine.impl.FlowExecut ionImpl.resume(
                org.springframework.webflow.executor.FlowExecutorI mpl.resumeExecution(
                org.springframework.webflow.mvc.servlet.FlowHandle rAdapter.handle(
                org.springframework.webflow.mvc.servlet.FlowContro ller.handleRequest(
                org.springframework.web.servlet.mvc.SimpleControll erHandlerAdapter.handle(SimpleControllerHandlerAda
                org.springframework.web.servlet.DispatcherServlet. doDispatch(
                org.springframework.web.servlet.DispatcherServlet. doService(
                org.springframework.web.servlet.FrameworkServlet.p rocessRequest(
                org.springframework.web.servlet.FrameworkServlet.d oPost(
                javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
                javax.servlet.http.HttpServlet.service(HttpServlet .java:717)