I want to clear textfield value dynamically
textField.setValue("")
we have done this but it not working it throws “NULL POINTER EXCEPTION” and below is our code
package com.company.sample.web.customer;
import com.haulmont.cuba.core.global.Metadata;
import com.haulmont.cuba.gui.components.AbstractEditor;
import com.company.sample.entity.Customer;
import com.haulmont.cuba.gui.components.FieldGroup;
import com.haulmont.cuba.gui.components.LookupField;
import com.haulmont.cuba.gui.components.TextField;
import com.haulmont.cuba.gui.data.Datasource;
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.Map;
public class CustomerEdit extends AbstractEditor<Customer> {
@Named("fieldGroup.age")
private TextField age;
@Override
public void init(Map<String, Object> params) {
age.addTextChangeListener(event -> {
if(event.getText().matches("[A-Za-z]+")) {
System.out.println("CHECKING...............................");
age.setValue("");
// showNotification(event.getText(),NotificationType.HUMANIZED);
}
});
}
}
Is there a reason you don’t have age
as an integer in the entity? If you do, CUBA will stop you putting non-numeric characters in the field by default.
It can be null, and you should check it first.
We have checked that but it is not working