Hi,
Following the book of Vaadin, I’m trying to make a ComboBox component which could
react (for the moment display a information box) as its value is changed.
What is expected is that as soon I’ve changed the combobox value, there is a message. However, with this code I need to change the value of CB and click on the arrow again in order the message to be displayed.
public class MyApp extends Application implements Property.ValueChangeListener {
HorizontalLayout mainView = new HorizontalLayout();
HorizontalLayout bannerMenu = new HorizontalLayout();
@Override
public void init() {
Window mainWindow = new Window("WorkeyVaadin");
SplitPanel vertSplit = new SplitPanel();
vertSplit.setLocked(true);
vertSplit.setHeight("100px");
vertSplit.setWidth("100%");
vertSplit.addComponent(bannerMenu);
vertSplit.addComponent(mainView);
new CBAvailableDocuments(bannerMenu);
mainWindow.addComponent(vertSplit);
setMainWindow(mainWindow);
}
public void valueChange(ValueChangeEvent event) {
bannerMenu.getWindow().showNotification("Selected city: " +
event.getProperty());
}
public class CBAvailableDocuments implements Property.ValueChangeListener {
private static final long serialVersionUID = 1L;
ComboBox cb;
public CBAvailableDocuments(AbstractComponentContainer container) {
cb = new ComboBox ("Sélectionnez un document");
String[] documents = new String[]
{ "Note de frais", "Fiche de
progrès", "Demande de congés", "Demande d'achat" };
container.addComponent(cb);
for (int i = 0; i < documents.length; i++) {
cb.addItem(documents[i]
);
}
cb.addListener(this);
//container.addListerner(this);
container.addComponent(cb);
}
@Override
public void valueChange(ValueChangeEvent event) {
cb.getWindow().showNotification("Selected city: " +
event.getProperty());
}
Regards,
Denis Boutin.