The conversion validator is a Struts field validator that checks if a type conversion error occurs for a field. For example, if the user inputs the value “one” for an integer field, a conversion error will occur, and an error message will be displayed next to the field. This validator can be used in either of the following forms:

 

1. Struts Conversion Validator XML

 Usage:

 

Parameters:

Parameter name

Description

fieldName

Name of the field to validate. Required if using plain validator syntax.

Struts Conversion Validator XML Examples:

 

2. Struts @ConversionErrorFieldValidator Annotation

Usage: Put the @ConversionErrorFieldValidatorannotation before the field’s setter/getter method or action method (in case of using plain-validator) in the following form:

@ConversionErrorFieldValidator (param1 = "param 1 value", param2 = "param 2 value", ...)

Parameters:

Parameter name

Required

Default value

Description

message

Yes

 

validation error message.

key

No

 

i18n key for validation error message.

messageParams

No

 

Additional parameters to customize the message.

fieldName

No

 

Specifies field name in case this validator type is plain-validator.

shortCircuit

No

false

Whether this validator is short circuit.

type

No

ValidatorType.FIELD

type of the validator: field-validator (FIELD) or plain-validator (SIMPLE).



 

Struts @ConversionErrorFieldValidator Annotation Examples:

 

Related Struts Form Validation Tutorials:

 

Other Struts Tutorials:


About the Author:

is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.