我对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”加载与所选“社会”的数据绑定,当“filiale”改变“名称”加载与数据绑定“社会”和“ filiale“选中。但是当我选择一个新的“社会”时,下面的代码开始
nome.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
getValuesFromDropDown();
}
});
我抓住了NullPointerException
String codfil = mapFiliale.get(filiale.getValue().toString()).toString();
谢谢。
答案 0 :(得分:1)
在societa监听器中,您调用nome.removeAllItems()。这将在nome AbstractSelect中触发Property.ValueChangeEvent。
societa.addListener(new Property.ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
filiale.removeAllItems();
caricaMenuFiliale();
nome.removeAllItems();
}
});