Rob Fox
Rob Fox

Reputation: 5571

Bind <select> to form in Playframework 2

How should I handle form requests with select elements in Playframework 2.0?

I have a form with this select:

@helper.select(deviceForm("deviceType"), options = options(deviceTypeList))

DeviceType is binded to public DeviceType deviceType; but deviceTypeList is a list of Strings

Upvotes: 0

Views: 1304

Answers (1)

Julien Richard-Foy
Julien Richard-Foy

Reputation: 9663

You can register a custom data binder for your type DeviceType:

Formatters.register(DeviceType.class, new Formatters.SimpleFormatter<DeviceType>() {

    @Override
    public DeviceType parse(String input, Locale l) throws ParseException {
        return …
    }

    @Override
    public String print(DeviceType deviceType, Locale l) {
        return …
    }
});

Upvotes: 3

Related Questions