Primefaces 4,动态菜单setCommand方法 [英] Primefaces 4, dynamic menu setCommand method

查看:169
本文介绍了Primefaces 4,动态菜单setCommand方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用primefaces 4,但是没有关于新MenuModel的文档.在这里, Optimus Prime 用一个小例子写了关于新菜单系统的文章. http://blog.primefaces.org/?p=2594

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 a little example. http://blog.primefaces.org/?p=2594

这时,他写了一个setCommand方法:

At this point, he wrote about a setCommand method:

这指向save方法(可在pf4展示柜中找到: http ://www.primefaces.org/showcase/ui/menu/menu.xhtml ):

This point to a save method (found in the pf4 showcase: http://www.primefaces.org/showcase/ui/menu/menu.xhtml):

介绍 之后,这是问题/问题.我正在从Bean创建动态菜单,但我不了解用户如何单击菜单并进行正确的操作.

After this introduction, here's the question/problem. I'm creating a dynamic menu from a bean but I don't understand how know the menu clicked by the user and do the right operation.

public void init() {
        if (spBean == null) {
            System.out.println("spBean is NULL!");
            return;
        }
        for (ServiceProvider sp: spBean.getListaSP()) {
            DefaultMenuItem item = new DefaultMenuItem(sp.getNome());
            //item.setUrl("#");
            item.setIcon("images/sps/" + sp.getImageId() + ".png");
            item.setCommand("#{dockMenuBackingBean.setNewMenu}");
            //
            model.addElement(item);
            System.out.println(sp.getNome());
        }
    }

    public void setNewMenu() {
        System.out.println("A menu was clicked BUT witch menu? Arghh!!");
        //
    }

我想做的是像在PF3.5中一样在ServiceProviderBackingBean中更改spSelected:

What I want to do, is to change the spSelected in ServiceProviderBackingBean, like I've done in PF3.5:

<p:dock>
    <c:forEach items="#{serviceProvidersBean.sps}" var="sp">
        <p:menuitem 
            value="#{sp.spInstanceName}" 
            icon="/images/sps/#{sp.spInstanceId}.png" 
            update=":form:spDetail" >
            <f:setPropertyActionListener 
                value="#{sp}"   
                target="#{serviceProvidersBean.spSelected}" />
        </p:menuitem>
    </c:forEach>
</p:dock>

有帮助吗?

实际上,我正在这样做,但是我正在寻找一种更好,更清洁的方法来实现这一目标.

Actually I'm doing this, but I'm looking for a better and cleaner way to achieve this.

public void init() {
    if (spBean == null) {
        System.out.println("spBean is NULL!");
        return;
    }
    for (ServiceProvider sp: spBean.getListaSP()) {
        DefaultMenuItem item = new DefaultMenuItem(sp.getNome());
        //item.setUrl("#");
        item.setIcon("images/sps/" + sp.getImageId() + ".png");
        String command = String.format("#{dockMenuBackingBean.setNewMenu('%d')}", spBean.getListaSP().indexOf(sp));
        item.setCommand(command);
        //
        model.addElement(item);
        System.out.println(sp.getNome());
    }
}

public void setNewMenu(Object x) {
    Integer selectedId = Integer.parseInt((String)x);
    System.out.println("Menu changed " + Integer.toString(selectedId));
    //
}

推荐答案

Optimus在这里,请使用setParam(key,value).不过,您需要为此更新到中继代码.

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

这篇关于Primefaces 4,动态菜单setCommand方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆