Example Custom TypeConverter
public class MyEnumeratedTypeConverter extends EnumeratedTypeConverter{
@Override
public MyEnum convert(String input, Class targetType, Collection errors) {
MyEnum type = //Your conversion logic here.
if(type == null){
errors.add(new ScopedLocalizableError("converter.enum", "notAnEnumeratedValue"));
}
return type;
}
}
@Override
public MyEnum convert(String input, Class targetType, Collection
MyEnum type = //Your conversion logic here.
if(type == null){
errors.add(new ScopedLocalizableError("converter.enum", "notAnEnumeratedValue"));
}
return type;
}
}
Once the class is defined, it needs to be wired up in the ActionBean. In the below snipped, note the converter param in the @Validate annotation.
Example Wire-Up
@Validate(required = false, on={"fetch"}, converter=MyEnumeratedTypeConverter.class)
public void setMyEnums(Collection myenums){
this.myenums = myenums;
}
public void setMyEnums(Collection
this.myenums = myenums;
}
See Also:
No comments:
Post a Comment