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();
}
}
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
public class FormattersProvider implements Provider<Formatters> (which does the conversion)public class FormattersModule extends AbstractModuleFormattersModule in application.confIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With