I trying to bind my Entity to a textfield
I have a Long field
@Column( name = “numero_registro_referencia”)
private Long numeroRegistroReferencia;public Long getNumeroRegistroReferencia() { return numeroRegistroReferencia;
}
public void setNumeroRegistroReferencia(Long numeroRegistroReferencia) {
this.numeroRegistroReferencia = numeroRegistroReferencia;
}
and try to bind just like this:
binderProtocolo.forField(numeroReg).withConverter( new StringToLongConverter(null,“Campo deve conter apenas números”)).bind(br.com.exmart.rtdpjlite.model.Protocolo::getNumeroRegistroReferencia, br.com.exmart.rtdpjlite.model.Protocolo::setNumeroRegistroReferencia);
I already try to put a 0L in null, but always returns same error:
java.lang.NullPointerException: value cannot be null
at java.util.Objects.requireNonNull(Objects.java:228) ~[na:1.8.0_162]
at com.vaadin.ui.AbstractTextField.setValue(AbstractTextField.java:97) ~[vaadin-server-8.3.1.jar:8.3.1]
at com.vaadin.ui.AbstractTextField.setValue(AbstractTextField.java:47) ~[vaadin-server-8.3.1.jar:8.3.1]
at com.vaadin.data.Binder$BindingImpl.initFieldValue(Binder.java:1071) ~[vaadin-server-8.3.1.jar:8.3.1]
at com.vaadin.data.Binder$BindingImpl.access$100(Binder.java:925) ~[vaadin-server-8.3.1.jar:8.3.1]
at com.vaadin.data.Binder.lambda$setBean$1(Binder.java:1547) ~[vaadin-server-8.3.1.jar:8.3.1]
at java.util.ArrayList.forEach(ArrayList.java:1257) ~[na:1.8.0_162]
at com.vaadin.data.Binder.setBean(Binder.java:1547) ~[vaadin-server-8.3.1.jar:8.3.1]
But my user can insert null (or don`t insert any value). How can I fix this?