The text lookup searches resource files from most specific to most generic, based on the current locale. When looking at the resource files, the key is the field name. If a corresponding resource is not found, the text specified by the @Text annotation is used.
In the following example, two LocalizableText fields are used to implement a simple validator.
public class Validator { "Value must be specified." )private static LocalizableText mustBeSpecifiedMessage; "Value must not be larger than {0}." )private static LocalizableText mustNotBeLargerThanMessage; static { LocalizableText.init( ExampleValidationService.class ); } public String validate( Integer value, Integer max ) { if( value == null ) { return mustBeSpecifiedMessage.text(); } else if( max != null && value.intValue() > max.intValue() ) { return mustNobeLargerThanMessage.format( max ); } return null; } }
If the locale is set to en_US, the search order will be as follows:
|
|