Hello, I am new to Vaadin, with only a few weeks under my belt, I’m impressed by alot of what it can do, but I am have a few fairly basic problems that are frustrating me, and I would appreciate any guidance.
The main problem at the moment is in the use of Forms to capture user input.
A button in my application launches a model dialog Window, the core code for the Dialog window is listed below:
public class MyDialog extends Window implements Button.ClickListener{
private final Button saveButton = new Button("save");
private final Button cancelButton = new Button("cancel");
MyBean myBean = new MyBean();
Form form = new Form();
private void initialise()
{
BeanItem<MyBean> item = new BeanItem<MyBean>(myBean);
form.setWriteThrough(false);
form.setInvalidCommitted(false);
form.setFormFieldFactory(new MyBeanFormFieldFactory());
form.setImmediate(true);
form.setItemDataSource(item);
// Add form to layout
addComponent(form);
// The cancel / apply buttons
HorizontalLayout buttons = new HorizontalLayout();
form.getLayout().addComponent(buttons);
buttons.addComponent(saveButton);
buttons.addComponent(cancelButton);
saveButton.addListener(this);
cancelButton.addListener(this);
}
public void buttonClick(ClickEvent event) {
if (event.getSource() == saveButton) {
try {
form.commit();
try {
businessDelegate.save(myBean);
parentWindow.removeWindow(this);
}
catch (Exception e) {
LOGGER.error(e.getLocalizedMessage(), e);
parentWindow.removeWindow(this);
}
}
catch (Exception e) {
// This is a validation error so ignore...
}
}
else {
LOGGER.debug("Cancel " + getCaption());
parentWindow.removeWindow(this);
}
}
}
If I type into the text fields of the dialog and click on the save button I get inconsistant outcomes:
It appears that the event handler is called before the values from the text box are submitted to the server-side, this must be because clicking the button does not post the form values to the server side in the way a regular web-application does do.
This problem makes my application difficult to use, as the user has to click back into the invalid text box and then click on a different componenet (presumably to cause a focus change type event to trigger the update) to pass validation and successfully submit the form.
My problem is worsened by the (deliberatly) slow connection I need to run over, so I really need an improved Form submit.
I hope I am using the Form component incorrectly and there is an easy solution the collective wisdom can advise.
Thank you.