Vaadin ValueChangeListener on the selected component is not working properly

I have a problem with ValueChangeListener . I have this code:

 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();} 

This piece of code controls listeners for società, filiale, and 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; } 

the sequence flow should be such that when changing “societa” select “filiale” - this is a download with data binding to the selected “society”, and when “filiale” changes “name”, this is loading with data binding to “society” and “community” “, filiale.” But when I select a new “society,” the code below starts

 nome.addListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { getValuesFromDropDown(); } }); 

and I will catch a NullPointerException on

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

in the getValuesFromDropDown () method. If I cancel this method call from valueChangeListener from select "nome", everything works fine. I know that my logic may have some problems, but I do not know why this behavior. Can anyone help me?

Thanks.

+4
source share
1 answer

In the societa listener, you call nome.removeAllItems (). This will call Property.ValueChangeEvent in nome AbstractSelect.

 societa.addListener(new Property.ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { filiale.removeAllItems(); caricaMenuFiliale(); nome.removeAllItems(); } }); 
+1
source

Source: https://habr.com/ru/post/1442706/


All Articles