Uploaded image for project: 'Spring Web Flow'
  1. Spring Web Flow
  2. SWF-1453

Support JSR303 Validation Groups for Webflow View States

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 2.3.0
    • Fix Version/s: 2.4.0.M1
    • Labels:
      None

      Description

      JSR-303 allows an array of validation groups (specified as Java types) to be passed in order to validate a subset of the constraints specified on a model object. This is useful in cases where the current user only updates a certain 'group' of properties on the model object and validation must be performed before proceeding.

      SWF 2.3.0 currently does not contain an API to specify validation groups on the model object for JSR-303 validation. However, this feature would be very useful.

        Issue Links

          Activity

          pawilson Paul Wilson created issue -
          rstoya05-aop Rossen Stoyanchev made changes -
          Field Original Value New Value
          Link This issue depends on SPR-7062 [ SPR-7062 ]
          Hide
          rstoya05-aop Rossen Stoyanchev added a comment -

          Web Flow relies on MVC SpringValidatorAdapter.validate(Object, Errors) for JSR 303 Bean Validation. It may be possible to provide some intermediate solution ahead of the Spring 3.1 final release. However we'd most likely need to wait for Spring 3.1 M2 at least to see the changes in SpringValidatorAdapter (SPR-7062).

          Show
          rstoya05-aop Rossen Stoyanchev added a comment - Web Flow relies on MVC SpringValidatorAdapter.validate(Object, Errors) for JSR 303 Bean Validation. It may be possible to provide some intermediate solution ahead of the Spring 3.1 final release. However we'd most likely need to wait for Spring 3.1 M2 at least to see the changes in SpringValidatorAdapter ( SPR-7062 ).
          rstoya05-aop Rossen Stoyanchev made changes -
          Assignee Keith Donald [ kdonald ] Rossen Stoyanchev [ rstoya05-aop ]
          Fix Version/s 2.3.1 [ 11849 ]
          Hide
          pawilson Paul Wilson added a comment - - edited

          I'm not sure I understand why the referenced JIRA is relevant. For model validation (which is what we are doing), groups applied to a @Valid doesn't make sense because the constraints on the target property's type will contain the groups. However for method validation (as used in the referred to JIRA), it looks like @Valid is used as a marker to instruct Spring MVC to perform model validation but there is no facility for specifying groups in this case (as I understand).

          For SWF, an attribute 'validation-groups' or similar allows us to specify the groups for model validation.

          I think the feature should allow multiple groups to be specified as unqualified names which refer either to inner types defined within the specified model object or types defined within the same package as the model object.

          Show
          pawilson Paul Wilson added a comment - - edited I'm not sure I understand why the referenced JIRA is relevant. For model validation (which is what we are doing), groups applied to a @Valid doesn't make sense because the constraints on the target property's type will contain the groups. However for method validation (as used in the referred to JIRA), it looks like @Valid is used as a marker to instruct Spring MVC to perform model validation but there is no facility for specifying groups in this case (as I understand). For SWF, an attribute 'validation-groups' or similar allows us to specify the groups for model validation. I think the feature should allow multiple groups to be specified as unqualified names which refer either to inner types defined within the specified model object or types defined within the same package as the model object.
          Hide
          pawilson Paul Wilson added a comment -

          Perhaps the following locations for groups should be supported for unqualified names:

          • As an inner type within the model object (e.g. 'GroupType' can resolve to ModelType$GroupType)
          • As an inner type within the model's type hierarchy, including within interfaces on the model or its supertypes
          • As an 'outer' type within the same package as the model object

          I think it would also be useful (and easy) to have Webflow resolve fully qualified types too.

          Show
          pawilson Paul Wilson added a comment - Perhaps the following locations for groups should be supported for unqualified names: As an inner type within the model object (e.g. 'GroupType' can resolve to ModelType$GroupType) As an inner type within the model's type hierarchy, including within interfaces on the model or its supertypes As an 'outer' type within the same package as the model object I think it would also be useful (and easy) to have Webflow resolve fully qualified types too.
          Hide
          framiere Florent Ramiere added a comment -

          See also issues SPR-6373, SPR-6369 and SPR-7847

          Show
          framiere Florent Ramiere added a comment - See also issues SPR-6373 , SPR-6369 and SPR-7847
          rstoya05-aop Rossen Stoyanchev made changes -
          Fix Version/s 2.3.1 [ 11849 ]
          Fix Version/s 2.4.0.M1 [ 12717 ]
          Hide
          rstoya05-aop Rossen Stoyanchev added a comment -

          Spring 3.1 added a SmartValidator with validationHints that we can build on for 2.4.

          Show
          rstoya05-aop Rossen Stoyanchev added a comment - Spring 3.1 added a SmartValidator with validationHints that we can build on for 2.4.
          rstoya05-aop Rossen Stoyanchev made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          tmarshall Trevor Marshall made changes -
          Workflow jira [ 45739 ] SPR Workflow [ 79366 ]
          Hide
          rstoya05-aop Rossen Stoyanchev added a comment -

          Support for this is now in master. Hints can be added as follows:

          <view-state id="state1" model="myModel" validation-hints="group1,group2">

          Each hint can be an inner Class either in the model type or its parent types, or a fully qualified class name. The hint "default" is reserved as the default validation group, i.e. javax.validation.groups.Default. The validation-hints property is an expression that can resolve to a String or an Object[] with Class instances. A custom ValidationHintResolver can also be plugged in through the flow-builder-services element to extend or replace the above algorithm.

          Show
          rstoya05-aop Rossen Stoyanchev added a comment - Support for this is now in master. Hints can be added as follows: < view -state id = "state1" model = "myModel" validation-hints = "group1,group2" > Each hint can be an inner Class either in the model type or its parent types, or a fully qualified class name. The hint "default" is reserved as the default validation group, i.e. javax.validation.groups.Default . The validation-hints property is an expression that can resolve to a String or an Object[] with Class instances. A custom ValidationHintResolver can also be plugged in through the flow-builder-services element to extend or replace the above algorithm.
          rstoya05-aop Rossen Stoyanchev made changes -
          Status In Progress [ 3 ] Resolved [ 5 ]
          Resolution Complete [ 8 ]
          Hide
          davids_s Sebastian Davids added a comment -

          In your example you forgot the single quotes:

          <view-state id="state1" model="myModel" validation-hints="'group1,group2'">

          Show
          davids_s Sebastian Davids added a comment - In your example you forgot the single quotes: < view -state id = "state1" model = "myModel" validation-hints = "'group1,group2'" >
          Hide
          ekfliu frank liu added a comment -

          Why is the hints on the view-state? Shouldn't that be on the transition? You could have different validation requirement depending on the transition.

          Show
          ekfliu frank liu added a comment - Why is the hints on the view-state? Shouldn't that be on the transition? You could have different validation requirement depending on the transition.
          Hide
          macs Massimo Franzoni added a comment -

          I agree with Frank Liu I can really benefit from a validation-hint at transition level ( logic could be if you specify both, the transition hint override the the view level hint ).
          Should I open a request enhancement?
          I imagine it in AbstractMvcView.getValidationHints(...) it has to execute getCurrenTransition() and read from that if there is the new attribute validationHint. I'm not an expert of spring inner logic but at first glance it does not seems complex.

          Show
          macs Massimo Franzoni added a comment - I agree with Frank Liu I can really benefit from a validation-hint at transition level ( logic could be if you specify both, the transition hint override the the view level hint ). Should I open a request enhancement? I imagine it in AbstractMvcView.getValidationHints(...) it has to execute getCurrenTransition() and read from that if there is the new attribute validationHint. I'm not an expert of spring inner logic but at first glance it does not seems complex.
          Hide
          arif Arif Mohammed added a comment - - edited

          Iam migrating my spring mvc application to use spring webflow and Iam seeing this limitation as show stopper. Is there any plan to fix this issue ?

          Here is my situation .....

          Iam using tabbed pane jsp page and on each tab I have an update button. On click of update button on particular tab, corresponding data need tobe validated.If it is a wizard kind of pages I would have navigated to different view states based on next/back buttons but since it is a single view state and has different transitions for each update button

          	<view-state id="showOperatorDetails" view="operator.view" model="operatorForm" validation-hints="'Personal,Educational,Business'">
          		<on-render>
          			<evaluate expression="operatorController.setModelAttributes(operatorForm)" />
          		</on-render>
          		<transition on="cancel" to="end" validate="false"/>
          		<transition on="updatePersonal" >	
          		  <evaluate expression="operatorController.updatePersonal(operatorForm)"/>
          		</transition>	
          		<transition on="updateEducational" >	
          		  <evaluate expression="operatorController.updateEducational(operatorForm)"/>
          		</transition>			
          		<transition on="updateBusiness" >	
          		  <evaluate expression="operatorController.updateBusiness(operatorForm)"/>
          		</transition>			
          	</view-state>

          Show
          arif Arif Mohammed added a comment - - edited Iam migrating my spring mvc application to use spring webflow and Iam seeing this limitation as show stopper. Is there any plan to fix this issue ? Here is my situation ..... Iam using tabbed pane jsp page and on each tab I have an update button. On click of update button on particular tab, corresponding data need tobe validated.If it is a wizard kind of pages I would have navigated to different view states based on next/back buttons but since it is a single view state and has different transitions for each update button < view -state id = "showOperatorDetails" view = "operator.view" model = "operatorForm" validation-hints = "'Personal,Educational,Business'" > < on -render> < evaluate expression = "operatorController.setModelAttributes(operatorForm)" /> </ on -render> < transition on = "cancel" to = "end" validate = "false" /> < transition on = "updatePersonal" > < evaluate expression = "operatorController.updatePersonal(operatorForm)" /> </ transition > < transition on = "updateEducational" > < evaluate expression = "operatorController.updateEducational(operatorForm)" /> </ transition > < transition on = "updateBusiness" > < evaluate expression = "operatorController.updateBusiness(operatorForm)" /> </ transition > </ view -state>
          Hide
          rstoya05-aop Rossen Stoyanchev added a comment -

          Massimo Franzoni, frank liu, yes please open a separate ticket.

          Show
          rstoya05-aop Rossen Stoyanchev added a comment - Massimo Franzoni , frank liu , yes please open a separate ticket.
          Hide
          macs Massimo Franzoni added a comment -

          I implemented this feature myself, I guess I could not wait almost a year for an answer

          Show
          macs Massimo Franzoni added a comment - I implemented this feature myself, I guess I could not wait almost a year for an answer
          Hide
          rstoya05-aop Rossen Stoyanchev added a comment -

          Fair enough. I've created SWF-1626.

          Show
          rstoya05-aop Rossen Stoyanchev added a comment - Fair enough. I've created SWF-1626 .
          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Open Open In Progress In Progress
          625d 22h 59m 1 Rossen Stoyanchev 15/Nov/12 8:35 AM
          In Progress In Progress Resolved Resolved
          14d 5h 57m 1 Rossen Stoyanchev 29/Nov/12 2:32 PM

            People

            • Assignee:
              rstoya05-aop Rossen Stoyanchev
              Reporter:
              pawilson Paul Wilson
            • Votes:
              8 Vote for this issue
              Watchers:
              14 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development