[play-framework] Custom binders in play

446 views
Skip to first unread message

Paweusz

unread,
Apr 16, 2010, 5:06:24 AM4/16/10
to play-framework
Is there a way to implement custom binder in play? I need to bind
BigDecimals in non standard format.

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.

Guillaume Bort

unread,
Apr 16, 2010, 5:43:33 AM4/16/10
to play-fr...@googlegroups.com
It's planned for the 1.1 to be able to specialize binding. But for now
you can't do it automatically. If you can't bind, just use the plain
old method.

Nicolas Leroux

unread,
Apr 16, 2010, 7:02:49 AM4/16/10
to play-fr...@googlegroups.com
Actually you can in the 1.1 but we will change it soon again so I would not recommend using the 1.1 at the moment.

Nicolas

Paweusz

unread,
Apr 16, 2010, 8:00:42 AM4/16/10
to play-framework
For 1.0.2 I created ugly workaround, but maybe it can help someone:
in my app I created package "play.data.binding" and class
"BigDecimalBinder implements SupportedType<BigDecimal>" with method:

public static void registerBinder() {
try {
Field stField = Binder.class.getDeclaredField("supportedTypes");
stField.setAccessible(true);
Map<Class<?>, SupportedType<?>> supportedTypes = (Map<Class<?>,
SupportedType<?>>) stField.get(null);
supportedTypes.put(BigDecimal.class, new BigDecimalBinder());
} catch (Exception e) {
throw new UnexpectedException(e);
}
}

then I call registerBinder from bootstrap job and have binder
registered.

On 16 Kwi, 13:02, Nicolas Leroux <nico...@lunatech.com> wrote:
> Actually you can in the 1.1 but we will change it soon again so I would not recommend using the 1.1 at the moment.
>
> Nicolas
> On 16 apr 2010, at 11:43, Guillaume Bort wrote:
>
>
>
> > It's planned for the 1.1 to be able to specialize binding. But for now
> > you can't do it automatically. If you can't bind, just use the plain
> > old method.
>
> > On Fri, Apr 16, 2010 at 11:06 AM, Paweusz <pawe...@gmail.com> wrote:
> >> Is there a way to implement custom binder in play? I need to bind
> >> BigDecimals in non standard format.
>
> >> --
> >> You received this message because you are subscribed to the Google Groups "play-framework" group.
> >> To post to this group, send email to play-fr...@googlegroups.com.
> >> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> >> For more options, visit this group athttp://groups.google.com/group/play-framework?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups "play-framework" group.
> > To post to this group, send email to play-fr...@googlegroups.com.
> > To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/play-framework?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/play-framework?hl=en.
Reply all
Reply to author
Forward
0 new messages