Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatters.register compile errors after upgrading from 2.4

I'm getting those strange 'non static' errors after upgrading from 2.4 to 2.5 when I run 'activator compile':

non-static method  <T>register(java.lang.Class<T>,play.data.format.Formatters.SimpleFormatter<T>) cannot be referenced from a static context

public MyController() {
    Formatters.register(Xpto.class, new XptoConverter());
}

XptoConverter:

public class XptoConverter extends SimpleFormatter<Xpto> {
  @Override
  public Xpto parse(String input, Locale l) throws ParseException {
    return new Xpto().setId(Long.valueOf(input));
  }

  @Override
  public String print(Xpto xpto, Locale l) {
    return xpto.getId().toString();
  }
}
like image 680
delki8 Avatar asked Jul 12 '26 01:07

delki8


1 Answers

The methods are not static any more; the Formatter is injected. See https://www.playframework.com/documentation/2.5.x/JavaForms#Register-a-custom-DataBinder. See also https://github.com/playframework/playframework/pull/5734

You have to

  1. Create a public class FormattersProvider implements Provider<Formatters> (which does the conversion)
  2. Create a public class FormattersModule extends AbstractModule
  3. Enable the FormattersModule in application.conf
like image 104
koppor Avatar answered Jul 14 '26 16:07

koppor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!