4

我有一个问题ValueChangeListener。我有这个代码:

private void caricaSelectMainUser(){
    Object[] a = socFilName.get(0);
    List<String> elencosoc = societaDao.getSocieta();
    List<String> socUtente = app.getUserDao().getSocietaByUname(app.getCod_utente());   

    for (int i = 0; i < elencosoc.size(); i++) {            
        societa.addItem(elencosoc.get(i));
    }            
    caricaMenuFiliale();
    caricaMenuRisorsa();
    societa.select(socUtente.get(0));   
    filiale.select(a[1]);
    nome.select(a[2]);

    societa.addListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            filiale.removeAllItems();
            caricaMenuFiliale();
            nome.removeAllItems();
        }   
    });   

    filiale.addListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            System.out.println("entro nel listener filiale");
            nome.removeAllItems();
            caricaMenuRisorsa();
        }   
    });       

    nome.addListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            getValuesFromDropDown();
        }   
    });       

    getValuesFromDropDown();}

这部分代码管理“società”、“filiale”和“name”的侦听器。

private void caricaMenuFiliale() {
    List<Object[]> elencofilNew = app.getUserDao().getDescFilialeSoc(societa.getValue().toString());
    mapFiliale = new HashMap<String,Object>();
    for (int i = 0; i < elencofilNew.size(); i++) {
        Object[] a = elencofilNew.get(i);
        for (int j = 0; j < a.length; j++) {
            mapFiliale.put(a[1].toString(), a[0]);
            filiale.addItem(a[1]);
        }
    }
}

private void caricaMenuRisorsa() {
    List<Object[]> elencoNominativiNew = app.getUserDao().getNominativiFromSoc(societa.getValue().toString());
    map = new HashMap<String,Object>();
    for (int i = 0; i < elencoNominativiNew.size(); i++) {
        Object[] a = elencoNominativiNew.get(i);
        map.put((String) a[0],a[1]);                        
        nome.addItem((String) a[0].toString());

    }
}

private void getValuesFromDropDown() {
    String codsoc = societa.getValue().toString();
    String codfil = mapFiliale.get(filiale.getValue().toString()).toString();
    String codper = map.get(nome.getValue()).toString();
    String mm = (mese.getValue().toString().length()==1?("0"+mese.getValue().toString())emoticonmese.getValue().toString()));
    String aaaamm = anno.getValue().toString() + mm;
}

顺序流程应该是,当“societa”更改时,选择“filiale”加载数据绑定与选定的“society”,当“filiale”更改“名称”加载数据绑定时选择“society”和“filiale” . 但是当我选择一个新的“社会”时,下面的代码开始

nome.addListener(new ValueChangeListener() {

    @Override
    public void valueChange(ValueChangeEvent event) {
        getValuesFromDropDown();
    }   
});    

我赶上NullPointerException

String codfil = mapFiliale.get(filiale.getValue().toString()).toString();

在 getValuesFromDropDown() 方法中。如果我从选择“nome”的 valueChangeListener 中取消此方法调用,一切正常。我知道我的逻辑可能有一些问题,但我不知道为什么会出现这种行为。有人可以帮我吗?

谢谢你。

4

1 回答 1

1

在社会监听器中,您调用 nome.removeAllItems()。这将触发名称 AbstractSelect 中的 Property.ValueChangeEvent。

societa.addListener(new Property.ValueChangeListener() {
    @Override
    public void valueChange(ValueChangeEvent event) {
        filiale.removeAllItems();
        caricaMenuFiliale();
        nome.removeAllItems();
    }   
});
于 2012-11-23T08:47:45.543 回答