|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.springmodules.validation.util.context.BasicContextAware
org.springmodules.validation.valang.parser.SimpleValangBased
org.springmodules.validation.valang.ValangValidator
public class ValangValidator
An implementation of Validator that takes a Valang syntax string
to define the set of validation rules it will apply. This instance is thread-safe.
The syntax of a Valang instruction is:
{ <key> : <expression> : <error_message> [ : <error_key> [ : <error_args> ] ] }
These instructions can be repeated and will be combined in a Validator instance. Each instruction will execute the expression on a target bean. If the expression fails the key will be rejected with the error message, error key and error arguments. If no error key is provided the key will be used as error key.
Some examples of the Valang syntax:
<bean id="myValidator" class="org.springmodules.validation.valang.ValangValidatorFactoryBean">
<property name="valang"><value><![CDATA[
{ age : ? is not null : 'Age is a required field.' : 'age_required' }
{ age : ? is null or ? >= minAge : 'Customers must be {0} years or older.' : 'not_old_enough' : minAge }
{ valueDate : ? is not null : 'Value date is a required field.' : 'valueDate_required' }
{ valueDate : ? is null or (? >= [T<d] and [T>d] > ?) :
'Value date must be today.' : 'valueDate_today' }
{ firstName : ? has text : 'First name is a required field.' : 'firstName_required' }
{ firstName : ? has no text or length(firstName) <= 50 :
'First name must be no longer than {0} characters.' : 'firstName_length' : 50 }
{ size : ? has length : 'Size is a required field.' }
{ size : ? has no length or upper(?) in 'S', 'M', 'L', 'XL' :
'Size must be either {0}, {1}, {2} or {3}.' : 'size_error' : 'S', 'M', 'L', 'XL' }
{ lastName : ? has text and !(false) = true :
'Last name is required and not false must be true.' }
]]></value></property>
</bean>
Custom property editors can be registered using org.springmodules.validation.valang.CustomPropertyEditor.
A custom visitor can be registered to use custom functions in the Valang syntax.
DefaultDateParser,
Validator| Field Summary |
|---|
| Fields inherited from class org.springmodules.validation.util.context.BasicContextAware |
|---|
applicationContext, applicationEventPublisher, beanFactory, messageSource, resourceLoader, servletContext |
| Constructor Summary | |
|---|---|
ValangValidator()
|
|
| Method Summary | |
|---|---|
void |
afterPropertiesSet()
|
java.util.Collection |
getRules()
|
void |
setCustomPropertyEditors(java.util.Collection customPropertyEditors)
Sets custom property editors on BeanWrapper instances (optional). |
void |
setDateParserRegistrations(java.util.Map dateParserRegistrations)
Deprecated. Use SimpleValangBased.setDateParsers(java.util.Map) instead. |
void |
setValang(java.lang.String valang)
This property sets the Valang syntax. |
boolean |
supports(java.lang.Class clazz)
|
void |
validate(java.lang.Object target,
Errors errors)
|
| Methods inherited from class org.springmodules.validation.valang.parser.SimpleValangBased |
|---|
addCustomFunction, createValangParser, findAllCustomFunctionsInApplicationContext, getAllCustomFunctions, getCustomFunctions, getDateParsers, initValang, setCustomFunctions, setDateParsers |
| Methods inherited from class org.springmodules.validation.util.context.BasicContextAware |
|---|
initLifecycle, initLifecycle, setApplicationContext, setApplicationEventPublisher, setBeanFactory, setMessageSource, setResourceLoader, setServletContext |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ValangValidator()
| Method Detail |
|---|
public void setValang(java.lang.String valang)
This property sets the Valang syntax.
valang - the Valang syntaxpublic void setCustomPropertyEditors(java.util.Collection customPropertyEditors)
Sets custom property editors on BeanWrapper instances (optional).
customPropertyEditors - the custom editors.BeanWrapper#registerCustomEditor(java.lang.Class, java.lang.String,
java.beans.PropertyEditor),
BeanWrapper#registerCustomEditor(java.lang.Class,
java.beans.PropertyEditor)public void setDateParserRegistrations(java.util.Map dateParserRegistrations)
SimpleValangBased.setDateParsers(java.util.Map) instead.
Sets date parser registrations (formats and modifiers) on DefaultDateParser (optional).
dateParserRegistrations - the date parser registrationsDefaultDateParser.register(String,
String),
DefaultDateParser.register(String,
DateModifier)public java.util.Collection getRules()
public void afterPropertiesSet()
throws java.lang.Exception
java.lang.Exceptionpublic boolean supports(java.lang.Class clazz)
public void validate(java.lang.Object target,
Errors errors)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||