DefaultMenuItem setCommand doesn't work
Posted: 09 Nov 2016, 13:59
I followed the the primefaces guide for making a dynamic menu. I need to set an ajax method on every menuItem, so I did this:
But it doesn't work. I put a breakpoint on onItemSelect() when I click on one menuItem but it doesn't stop on it, so I think it doesn't work. I also tried to set some parameters, in fact I need to know what's the selected item. I also tried to set a String on setCommand that didn´t have the parentheses but this way it also didn´t work.
Thanks.
Code: Select all
/* Costruttore */
public MenuBean() {
this.model = new DynamicMenuModel();
}
@Override
protected void initBeanData()
{
try {
PrsfgApplicationURLEnum[] tabModel = PrsfgApplicationURLEnum.values();
DefaultSubMenu firstSubmenu = new DefaultSubMenu();
for(PrsfgApplicationURLEnum item : tabModel) {
DefaultMenuItem dmi = new DefaultMenuItem(item.getLabel());
dmi.setId(item.getLabel());
dmi.setUrl(item.getUrl());
dmi.setCommand("#{menuBean.onItemSelect()}");
// dmi.setParam("appName", new String(item.getLabel()));
// dmi.setUpdate("@(.fittiziaLayout)");
firstSubmenu.addElement(dmi);
}
model.addElement(firstSubmenu);
} catch(Exception e) {
log.error("Errore in fase di creazione del modello del tab menu");
log.error(e.getMessage());
e.printStackTrace();
}
}
public void onItemSelect() {
System.out.println("");
this.selectedApplication = ""; //event.getMenuItem().getParams().get("appName").get(0);
}
Thanks.