[SWF-1453] Support JSR303 Validation Groups for Webflow View States Created: 28/Feb/11  Updated: 27/Mar/14  Resolved: 29/Nov/12

Status: Resolved
Project: Spring Web Flow
Component/s: Binding: Validation System
Affects Version/s: 2.3.0
Fix Version/s: 2.4.0.M1

Type: Improvement Priority: Major
Reporter: Paul Wilson Assignee: Rossen Stoyanchev
Resolution: Complete Votes: 8
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depend
depends on SPR-7062 Add Group Class support to JSR-303 Va... Resolved
Reference URL: http://forum.springsource.org/showthread.php?p=348316&posted=1#post348316

 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.



 Comments   
Comment by Rossen Stoyanchev [ 28/Feb/11 ]

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).

Comment by Paul Wilson [ 28/Feb/11 ]

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.

Comment by Paul Wilson [ 01/Mar/11 ]

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.

Comment by Florent Ramiere [ 11/Mar/11 ]

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

Comment by Rossen Stoyanchev [ 15/Dec/11 ]

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

Comment by Rossen Stoyanchev [ 29/Nov/12 ]

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.

Comment by Sebastian Davids [ 17/Mar/13 ]

In your example you forgot the single quotes:

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

Comment by frank liu [ 03/May/13 ]

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.

Comment by Massimo Franzoni [ 23/May/13 ]

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.

Comment by Arif Mohammed [ 06/Sep/13 ]

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>

Comment by Rossen Stoyanchev [ 17/Mar/14 ]

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

Comment by Massimo Franzoni [ 17/Mar/14 ]

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

Comment by Rossen Stoyanchev [ 17/Mar/14 ]

Fair enough. I've created SWF-1626.

Generated at Sat Nov 25 11:11:10 UTC 2017 using JIRA 6.4.14#64029-sha1:ae256fe0fbb912241490ff1cecfb323ea0905ca5.