Loading ComboBox

hello,
This is my first post in forum Vaadin,
I have a problem with loading the comboBox,
My combo Project is supported by the choice of combo previous Customer, the loading is done from the base.
So if I rush to select a project after selecting a client I get a gray list as shown in Figure 1 and if I click another list appears correctly as shown in Figure 2.
I think this is a behavior Vaadin, right?
Is there a solution?
Thank you for any help.
oops I forgot to mention that I use the latest version of Vaadin 6.7.6.
Regards
12277.jpg
12278.jpg

Erm : your problem is not very clear, but I suspect you simply need to setImmediate(true) on all of the combo-boxes.

Thank you Anthony for the answer very quickly.
I use setImmediate (true).
Here is some code that gives the same result as I have.


/*
 * MyApplication.java
 *
 * Created on 10 avril 2012, 16:38
 */
package com.example.vaadin;

import com.vaadin.Application;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.ui.AbstractSelect;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Label;
import com.vaadin.ui.Window;

/**
 *
 * @author Administrateur
 * @version
 */
public class MyApplication extends Application {

    Window mainWindow = new Window("Test Loading CoboBox");
    Label label = new Label("This is a test");
    ComboBox combo1 = new ComboBox("Combo 1 :");
    ComboBox combo2 = new ComboBox("Combo 2 :");

    @Override
    public void init() {
        setTheme("theme");
        combo1.setWidth("250px");
        combo1.setNullSelectionAllowed(false);
        combo1.setImmediate(true);
        combo1.setFilteringMode(AbstractSelect.Filtering.FILTERINGMODE_CONTAINS);
        combo1.addItem("Item 1");
        combo1.addItem("Item 2");
        combo1.addItem("Item 3");
        combo2.setWidth("250px");
        combo2.setNullSelectionAllowed(false);
        combo2.setImmediate(true);
        combo2.setFilteringMode(AbstractSelect.Filtering.FILTERINGMODE_CONTAINS);
        combo1.addListener(new ComboBox.ValueChangeListener() {

            public void valueChange(ValueChangeEvent event) {
                try {
                    Thread.sleep(2000); // simulation of database query execution
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
                String value = (String) event.getProperty().getValue();
                combo2.removeAllItems();
                for (int i = 0; i < 500; i++) {
                    String s = value + "   " + "Loading ... " + i;
                    combo2.addItem(s);
                }
            }
        });
        mainWindow.addComponent(label);
        mainWindow.addComponent(combo1);
        mainWindow.addComponent(combo2);
        setMainWindow(mainWindow);
    }
}

to summarize, if I try to open the combo before it is loaded I get a gray list.
Can someone help me!

to summarize, if I try to open the combo before it is loaded I get a gray list.
Can someone help me!

Hi mallek,

I suspect that the problem could be on how you populate the container (ComboBox), I had got the same issue on my application and I solve it by using the addAll method instead of addItem, but I use a BeanItemContainer, also you can play with setEnabled on your second combo box, try something like this (I use your same example and works fine, the selection is available when the ComboBox is populated):


/*
* MyApplication.java
*
* Created on 10 avril 2012, 16:38
*/
package com.example.vaadin;

import com.vaadin.Application;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.ui.AbstractSelect;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Label;
import com.vaadin.ui.Window;

/**
*
* @author Administrateur
* @version
*/
public class MyApplication extends Application {

    Window mainWindow = new Window("Test Loading CoboBox");
    Label label = new Label("This is a test");
    ComboBox combo1 = new ComboBox("Combo 1 :");
    ComboBox combo2 = new ComboBox("Combo 2 :");

    @Override
    public void init() {
        setTheme("theme");
        combo1.setWidth("250px");
        combo1.setNullSelectionAllowed(false);
        combo1.setImmediate(true);
        combo1.setFilteringMode(AbstractSelect.Filtering.FILTERINGMODE_CONTAINS);
        combo1.addItem("Item 1");
        combo1.addItem("Item 2");
        combo1.addItem("Item 3");
        combo2.setWidth("250px");
        combo2.setNullSelectionAllowed(false);
        combo2.setImmediate(true);
        combo2.setFilteringMode(AbstractSelect.Filtering.FILTERINGMODE_CONTAINS);
        combo2.setEnabled(false);
        combo1.addListener(new ComboBox.ValueChangeListener() {

            public void valueChange(ValueChangeEvent event) {
                try {
                    Thread.sleep(2000); // simulation of database query execution
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
                String value = (String) event.getProperty().getValue();
                combo2.removeAllItems();
                for (int i = 0; i < 500; i++) {
                    String s = value + "   " + "Loading ... " + i;
                    combo2.addItem(s);
                }
                combo2.setEnabled(true);
            }
        });
        mainWindow.addComponent(label);
        mainWindow.addComponent(combo1);
        mainWindow.addComponent(combo2);
        setMainWindow(mainWindow);
    }
}

HTH.

Javi

Hi again,

Other choice you can use is an IndexedContainer, the time spent in ComboBox loading should be better.

Using the same Example, only the listener method.


        combo1.addListener(new ComboBox.ValueChangeListener() {

            public void valueChange(ValueChangeEvent event) {
                try {
                    Thread.sleep(2000); // simulation of database query execution
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
                String value = (String) event.getProperty().getValue();
                combo2.removeAllItems();
                List<String> combo2Items = new ArrayList<String>();
                for (int i = 0; i < 500; i++) {
                    String s = value + "   " + "Loading ... " + i;
                    combo2Items.add(s);
                }
                IndexedContainer cmb2Container = new IndexedContainer(combo2Items);
                combo2.setContainerDataSource(cmb2Container);
                combo2.setEnabled(true);
            }
        });

HTH.

Javi

here’s the way I filled my container.


private void fillComboProjet(Client cl) throws Exception {
        containerProjets = new BeanItemContainer<Projets>(Projets.class);
        try {
            List list = dataSelect.getProjetsByClient(cl);
            containerProjets.addAll(list);
            comboProjet.setContainerDataSource(containerProjets);
            comboProjet.setItemCaptionPropertyId("libProj");
        } catch (Exception ex) {
            throw ex;
        }
    }

it does not regulate the concern: (.
the same piece of code that you sent me, I’m sorry but it does not work.

Hi,

Which version of vaadin are you using?

Javi

Hi,
I use version 6.7.6, the last.
is what you have produced the bug I have??
I say rather an anomaly display as soon as I give you time to combo to load everything is ok.
behavior for gray list must essaier expand the list before it is loaded (be very soon).