lisak
lisak

Reputation: 21981

PropertyEditor not for Type conversion but String manipulation

I'm feeling kinda lost when it comes to String type with Property editors and string transformation. PropertyEditors and Conversion services are based on type of properties. But what about when it is needed to transform string to a different string ? If the field is of Date type, CustomDatePropertyEditor is applied, the conversion will be always the same, String to Date, but if we want to convert string A to string B, then we want it to happen only to a particular field, but it would do that for all fields of type String. There is no way of saying which field to convert / transform by this PropertyEditor.

For instance, I'm getting 1 or 0 request parameters from a UI html form widget and I'd need to bind it to a bean as PM or AM. How would I do that ?

Upvotes: 0

Views: 323

Answers (1)

Ali
Ali

Reputation: 12684

Try this:

@InitBinder
public void initBinder(WebDataBinder binder) {
    binder.registerCustomEditor(String.class, "field1", new PropertyEditorSupport() { });
}

that way it only applies to "field1" of type String.

Upvotes: 1

Related Questions