简体   繁体   中英

Spring Webflow model validation.

We have developed an internet bank project in our company. We have used spring-mvc in this project and all of property validations have been carried out using Hibernate validator. However for some of our services that have a state-machine nature, we need to use spring-webflow.

In doing so we need to validate models in spring webflow without adding any extra validators. As you know There are 2 ways to validate a model programmatically:

  1. Define validation logic in the model object.
  2. Define a separate object called Validator to validate the model.

However, we DO NOT want to use none of these validation techniques.

For example lets imagine we had a Class named Customer. We used annotation validation for the properties in this class in our project. Now, we want to use this class as a model in view states in our webflow.

I was wondering if someone could help us how to validate models in spring webflow using annotation validation with hibernate validator.

Spring Webflow 2.4 supports JSR-303 validation and partial validation through the use of validation groups.

You need to add the following to the application context xml file:

<webflow:flow-registry flow-builder-services="flowBuilderServices" />

<webflow:flow-builder-services id="flowBuilderServices" validator="validator" />

<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />

This will allow you to validate your model objects using annotations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM