Hi!
I have my java bean that I want to store values into.
@Data
public class AllComponents implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
// For start and stop view
private String[] deviceList;
private String temperature1;
private String temperature2;
private String temperature3;
private String temperature4;
private boolean checkbox1;
private boolean checkbox2;
private boolean checkbox3;
private boolean checkbox4;
private String startStop;
// For database view
private String[] sampleTimes;
private String urlServer;
private String userName;
private String dataBaseName;
private String tableName;
private String connectDisconnet;
private String password;
}
And I set the connection between Vaadin components and my Java bean like this. It’s a Spring Boot application where I begin to load all the components at the start and make them global as well. The problem is that I cannot bind checkboxX
, connectDisconnect
, deviceList
and sampleTimes
. I got the following error message.
The method bind(HasValue<?,FIELDVALUE>, String) in the type Binder<AllComponents> is not applicable for the arguments (Checkbox, AllComponents::isCheckbox1)
The method bind(HasValue<?,FIELDVALUE>, ValueProvider<AllComponents,FIELDVALUE>, Setter<AllComponents,FIELDVALUE>) in the type Binder<AllComponents> is not applicable for the arguments (Select<String>, AllComponents::getSampleTimes, AllComponents::setSampleTimes)
The method bind(HasValue<?,FIELDVALUE>, ValueProvider<AllComponents,FIELDVALUE>, Setter<AllComponents,FIELDVALUE>) in the type Binder<AllComponents> is not applicable for the arguments (Button, AllComponents::getConnectDisconnet, AllComponents::setConnectDisconnet)
The method bind(HasValue<?,FIELDVALUE>, ValueProvider<AllComponents,FIELDVALUE>, Setter<AllComponents,FIELDVALUE>) in the type Binder<AllComponents> is not applicable for the arguments (Select<String>, AllComponents::getDeviceList, AllComponents::setDeviceList)
What am I doing wrong here? Sure, I know that it’s not an applicable argument. But what should I do? The poruse with this style of programming is that I’m going to serialize and deserialize the java bean object to a file. Like saving the properties of the Vaadin components.
@Component
@Order(0)
@Data
public class InitialStartUp implements ApplicationListener<ContextRefreshedEvent> {
public static final String SER_DER_PATH = "AllComponents.ser";
public static final String START = "Start";
public static final String STOP = "Stop";
public static final String CONNECT = "Anslut";
public static final String DISCONNECT = "Koppla ifrån";
// The reason why I have written this project like this
// it's because of the ability to auto starting and global connection for the Vaadin components
// For the Start_Stop class - Set the default values
private Select<String> deviceList = new Select<String>(devices());
private TextField temperature1 = new TextField();
private TextField temperature2 = new TextField();
private TextField temperature3 = new TextField();
private TextField temperature4 = new TextField();
private Checkbox checkbox1 = new Checkbox();
private Checkbox checkbox2 = new Checkbox();
private Checkbox checkbox3 = new Checkbox();
private Checkbox checkbox4 = new Checkbox();
private Button startStop = new Button(START);
// For the Database class
private Select<String> sampleTimes = new Select<String>(new String[] {"1", "10", "30", "60", "120", "600", "1800", "3600"});
private TextField urlServer = new TextField();
private TextField userName = new TextField();
private TextField dataBaseName = new TextField();
private TextField tableName = new TextField();
private Button connectDisconnet = new Button(CONNECT);
private PasswordField password = new PasswordField();
// Field that we want to save to file. It contains all the Vaadin components properties
private AllComponents allComponents;
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
// Check if we have created the storage file
createFileIfNotExist(SER_DER_PATH);
// Binds the field to AllComponents class
Binder<AllComponents> binder = new Binder<>(AllComponents.class);
binder.bind(deviceList, AllComponents::getDeviceList, AllComponents::setDeviceList);
binder.bind(temperature1, AllComponents::getTemperature1, AllComponents::setTemperature1);
binder.bind(temperature2, AllComponents::getTemperature2, AllComponents::setTemperature2);
binder.bind(temperature3, AllComponents::getTemperature3, AllComponents::setTemperature3);
binder.bind(temperature4, AllComponents::getTemperature4, AllComponents::setTemperature4);
binder.bind(checkbox1, AllComponents::isCheckbox1);
binder.bind(checkbox2, AllComponents::isCheckbox2);
binder.bind(checkbox3, AllComponents::isCheckbox3);
binder.bind(checkbox4, AllComponents::isCheckbox4);
binder.bind(startStop, AllComponents::getStartStop);
binder.bind(sampleTimes, AllComponents::getSampleTimes, AllComponents::setSampleTimes);
binder.bind(urlServer, AllComponents::getUrlServer, AllComponents::setUrlServer);
binder.bind(userName, AllComponents::getUserName, AllComponents::setUserName);
binder.bind(dataBaseName, AllComponents::getDataBaseName, AllComponents::setDataBaseName);
binder.bind(tableName, AllComponents::getTableName, AllComponents::setTableName);
binder.bind(connectDisconnet, AllComponents::getConnectDisconnet, AllComponents::setConnectDisconnet);
binder.bind(password, AllComponents::getPassword, AllComponents::setPassword);
// Set connection
allComponents = new SerDer().deserialization(SER_DER_PATH);
binder.setBean(allComponents);
}