17500

Spring webflow partial validation

Question:

I am trying to implement partial validation in Spring Webflow 2.4. According to their reference manual the validation should be done very simply using groups:

@NotNull @Size(min = 2, max = 30, groups = State1.class) private String name;

In my understanding the State1 should be the ID of view-state in which the model should be validated. So the definition of this view state in flow.xml would look like this:

<view-state id="state1" model="modelObject"/>

I was trying to define the State1 as an inner class of my model object, but without success.

The Webflow reference doesn't provide full manual for partial validation, so my question is: Am I missing something? Does anybody have experience with using the partial validation using JSR303 groups?

Thanks, Shimon

Answer1:

I think I can answer my own question now :)

The root of the problem was in 2 things:

<ol><li>

The Group1 should be an inner interface of model object. So the model object class should look something like this:

public clas ModelObject{ @NotEmpty(groups=Group1.class) private String field1; public interface Group1{} } </li> <li>

the name od validation-hint should be in single quotes

validation-hints="'group1'" </li> </ol>

Answer2:

<em>"In my understanding the State1 should be the ID of view-state in which the model should be validated."</em>

Here groups is not referring to view-state id. It is an inner class or parent or interface implemented by model object.

To realize JSR-303 partial validations, in SWF 2.4 onwards(this is the version SWF starts supporting it), you need to specify validation-hints as:

<view-state id="someView" model="modelObject" validation-hints="group1,group2">

where group1, group2 can be inner Class either in the model type modelObject or its parent types or interfaces implemented by modelObject.

As per the documentation <a href="http://docs.spring.io/spring-webflow/docs/2.4.x/reference/html/views.html#view-validation-jsr303-partial" rel="nofollow">here</a>:

Each hint can be an inner Class either in the model type or its parent types. For example, given org.example.MyModel with inner type Group1 and Group2 you can specify the hints "group1", "group2" or both "group1,group2". A hint can also be a fully qualified class name. The hint "default" indicates the default validation group, i.e. javax.validation.groups.Default. Also, the validation-hints property can be an expression that resolves to a String or an Object[] containing Class based hints.

Recommend

  • Accents printed differently every time, in PHP and HTML
  • Change a specific row in a ArrayAdapter ListView Android
  • Limit SQL query to only the top two counts per group [duplicate]
  • Best way to validate and extend constructor parameters in Scala 2.10
  • What could cause an assignment to not work?
  • How to make lenses for records with type-families [duplicate]
  • jQuery validate: submitting form only when fields are validated
  • What is the best way to include a style sheet for a specific page?
  • XNU incudes in Kext
  • how to read a file in prolog?
  • Streaming screenshots over WebRTC as a video stream from iOS
  • Runtime.exec() gives Error: Could not find or load main class
  • quiver not drawing arrows just lots of blue, matlab
  • Salesforce Different WSDL files and when to use
  • Sencha Touch 2.0 Controller refs attribute not working?
  • VSO Build — Response status code does not indicate success: 404 (Not Found)
  • When to use `image` and when to use `Matrix` in Emgu CV?
  • What is the “return” in scheme?
  • Which linear programming package should I use for high numbers of constraints and “warm starts” [clo
  • Build own AppleScript numerical error handling
  • jquery mobile loadPage not working
  • Apache 2.4 - remove | delete | uninstall
  • AT Commands to Send SMS not working in Windows 8.1
  • How to delete a row from a dynamic generate table using jquery?
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Proper way to use connect-multiparty with express.js?
  • Trying to get generic when generic is not available
  • How do I configure my settings file to work with unit tests?
  • embed rChart in Markdown
  • How to stop GridView from loading again when I press back button?
  • How to get Windows thread pool to call class member function?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Is it possible to post an object from jquery to bottle.py?
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal