Primefaces 4, dynamic menu setCommand method

前端 未结 2 436
北海茫月
北海茫月 2020-12-17 19:23

I\'m trying primefaces 4 but there are no documentation around for the new MenuModel. Here, Optimus Prime wrote about the new menu system with

相关标签:
2条回答
  • 2020-12-17 19:49

    Setting command parameters by setParam(key,value) can be done like that:

    In your menu generating bean:

    DefaultMenuItem item = new DefaultMenuItem("display list");
    item.setId("listMenuItem");
    item.setCommand("#{myBean.displayList}");
    item.setParam("listId", 1l);
    

    In your managed bean containing the action:

    public String displayList(ActionEvent event) {
        MenuItem menuItem = ((MenuActionEvent) event).getMenuItem();
        Long id = Long.parseLong(menuItem.getParams().get("listId").get(0));
        findListBy(id);
    }
    

    Reading parameters seems to be a bit complicated. But ActionListeners aren't supported by Primefaces 4 MenuItems (because they aren't derived from UICommand any more) so params seem to be new new way.

    0 讨论(0)
  • 2020-12-17 19:57

    Optimus here, use setParam(key,value). You need to update to trunk code though for this.

    0 讨论(0)
提交回复
热议问题