I’m trying to do a exercice with Grid and the Binder class like a Alejandro’s exercice. This is my architecture:
(https://ibb.co/kGQkgd)
I did a bit changes, I use “Principal.java” to select what screen loads to them refill the form. Finally I put the Grid in “Resumen.java”.
(https://ibb.co/iEcbnJ)
My problem is that allways, in the next file, the binder objects is null:
package com.example.Vistas;
import com.example.DTOs.SegurosDTO;
import com.example.Enums.Religion;
import com.example.Services.SegurosService;
import com.vaadin.data.Binder;
import com.vaadin.navigator.View;
import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBoxGroup;
import com.vaadin.ui.DateField;
import com.vaadin.ui.FormLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.NativeSelect;
import com.vaadin.ui.RadioButtonGroup;
import com.vaadin.ui.TextField;
import com.vaadin.ui.themes.ValoTheme;
public class FormularioIncendio extends FormLayout implements View{
private SegurosService segurosService = SegurosService.getInstance();
private SegurosDTO segurosDTO;
private Binder<SegurosDTO> binder = new Binder<>(SegurosDTO.class);
// Componentes del Form
private TextField tipo = new TextField("Tipo seguro:");
private TextField titular = new TextField("Titular:");
private DateField hasta = new DateField("Válido hasta:");
private NativeSelect<Religion> religion = new NativeSelect<>("Religión");
private RadioButtonGroup<String> enfermo = new RadioButtonGroup<>("¿Le gustan las cerillas?:");
private CheckBoxGroup<String> actividades = new CheckBoxGroup<>("Prefernecias deportivas:");
private Button salvar = new Button("Salvar");
private Button limpiar = new Button("Borrar");
private Resumen resumenLocal;
public FormularioIncendio(Resumen resumen) {
this.resumenLocal = resumen;
HorizontalLayout botonera = new HorizontalLayout(salvar, limpiar);
addComponents(tipo, titular, hasta, religion, enfermo, actividades, botonera);
//----------- Configuracion de Valores -----------
// Setteo de tipo
tipo.setEnabled(false);
tipo.setValue("Incendio");
// Carga del "Combo" de religion
religion.setItems(Religion.values());
//---------- Propio del tipo -------------
// Carga de RadioButton
enfermo.setItems("Si", "No");
// Carga de multiselección
actividades.setItems("Cazar gamusinos", "Puenting", "Leer Biblia");
//----------------------------------------
salvar.setStyleName(ValoTheme.BUTTON_FRIENDLY);
limpiar.setStyleName(ValoTheme.BUTTON_DANGER);
binder.bindInstanceFields(this);
limpiar.addClickListener(e -> this.limpiarClick());
salvar.addClickListener(e -> this.salvarClick());
setMargin(true);
}
private void limpiarClick() {
titular.clear();
hasta.clear();
religion.clear();
enfermo.clear();
actividades.clear();
}
private void salvarClick() {
segurosService.save(segurosDTO);
this.limpiarClick();
}
}
Can someone explain me where is the problem?, thanks a lot
I followed this tutorial in my first try but now I use other architecture. Following the example I could run the application correctly but with finally with my reorder I have been to use other way to set the class without Binder. I used the typical setter.