Textfield values sometimes not coming thru after I edit them and button click event
I am trying run the demo of the hibernate with vaadin from
http://vaadin.com/wiki/-/wiki/Main/Using%20Hibernate%20with%20Vaadin?p_r_p_185834411_title=Using+Hibernate+with+Vaadin
I installed it and the GUI works, but there is a problem: When I double click on a row in the table, it pops up the ‘Edit Window’ and I edit the textfields ‘kilometers’ and ‘title’ putting some values and click on SAVE button. After the save, the values are not stored. Sometimes it works and sometimes it does. Sometime only of the textfield either title or kilometer field is being saved.
What is the problem? I put a breakpoint in buttonClick(ClickEvent event) at this line 56
} else if (event.getButton() == save) {
And here I find the textfield value is sometimes comes correct and other times has previous old value.
See this WorkoutEditor.java below
public class WorkoutEditor extends Window implements ClickListener {
private static final long serialVersionUID = 6569779390222502305L;
private DateField date = new DateField("Date");
private TextField kilomiters = new TextField("Kilometers");
private TextField title = new TextField("Title/note");
private Button save = new Button("Save");
private Button delete = new Button("Delete");
private Workout run;
private WorkoutLog workoutLog;
public WorkoutEditor(WorkoutLog app) {
super("Edit workout popup");
workoutLog = app;
this.setImmediate(true);
this.title.setImmediate(true);
this.kilomiters.setImmediate(true);
Layout main = new VerticalLayout();
this.setContent(main); // deprecated setLayout(main);
main.setSizeUndefined();
main.setStyleName(Panel.STYLE_LIGHT);
FormLayout form = new FormLayout();
form.setSizeUndefined();
date.setResolution(DateField.RESOLUTION_MIN);
form.addComponent(date);
form.addComponent(kilomiters);
form.addComponent(title);
main.addComponent(form);
HorizontalLayout actions = new HorizontalLayout();
actions.addComponent(save);
save.addListener(this);
actions.addComponent(delete);
delete.addListener(this);
main.addComponent(actions);
}
public void loadRun(Workout run) {
if (run == null) {
close();
} else {
date.setValue(run.getDate().clone());
kilomiters.setValue("" + run.getKilometers());
title.setValue("" + run.getTitle());
if (getParent() == null) {
workoutLog.getMainWindow().addWindow(this);
}
kilomiters.focus();
this.run = run;
}
}
public void buttonClick(ClickEvent event) {
if (event.getButton() == delete) {
workoutLog.deleteRow(run);
} else if (event.getButton() == save) {
run.setDate((Date) this.date.getValue());
run.setKilometers(Float.parseFloat(this.kilomiters.getValue().toString()));
run.setTitle((String) this.title.getValue());
workoutLog.persistRow(run);
}
if (getParent() != null) {
((Window) getParent()).removeWindow(this);
}
}
}