如何制作Primefaces动态工具栏 [英] How to make a primefaces dynamic toolbar

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

问题描述

自上周以来,我一直在使用PrimeFaces 3.1.1,它似乎是一个出色的视觉组件框架.我正在从Richfaces进行迁移,并尝试使所有功能仅适用于Prime和JSF2(2.1.6版).

我的问题来自必须实现的动态工具栏.有些操作直接集成在工具栏上(commandButtons),而其他操作内部有一些子操作,因此我必须使用操作名称来做一个menuButton,并像菜单项一样在这里添加每个单独的操作.这是我的代码:

 <h:panelGroup id="Texto_Header" layout="block">
        <h:form>
            <p:toolbar>
                <p:toolbarGroup>
                    <!-- Operaciones de aplicación -->
                    <ui:repeat value="#{logedBean._apps}" var="opBean">
                            <!-- OPERACION PRINCIPAL EJECUTABLE -->
                            <h:panelGroup rendered="#{opBean._Clickable}">
                                <p:commandButton ajax="true" value="#{opBean._Nombre}"
                                    action="#{opBean.actionOperationClick}" />
                            </h:panelGroup>
                            <!-- OPERACION PRINCIPAL CON SUBOPERACIONES -->
                            <h:panelGroup rendered="#{!opBean._Clickable}">
                                <p:menuButton value="#{opBean._Nombre}">
                                    <ui:repeat value="#{opBean._subOperaciones}" var="opBean2">
                                        <p:menuitem ajax="true" value="#{opBean2._Nombre}"
                                            actionListener="#{opBean2.actionOperationClick}" />
                                    </ui:repeat>
                                </p:menuButton>
                            </h:panelGroup>
                    </ui:repeat>
                </p:toolbarGroup>
            </p:toolbar>
        </h:form>
    </h:panelGroup>
 

我的问题是我只得到第一个操作组件,它正确呈现了CommandButtons并且它们的动作正常,但是在#{!opBean._Clickable}"的情况下,我得到了一个名为menuButton的名称,但里面没有菜单项.似乎嵌入的ui:repeat迭代没有很好地完成.

我尝试使用 c:foreach c:choose c:otherwise 标记获得相同的机会,在这种情况下,我得到了菜单在外观上做得很好,commandButton动作也运行良好,但是当我单击menuItem时,它表示无法识别opBean2.但是正如我之前所说,我更喜欢只使用JSF标记.有办法吗?

解决方案

我终于设法使其与jsp迭代标记一起使用,并更改了菜单项标记的actionListener属性作为动作属性.这是我的代码:

     <h:panelGroup id="Texto_Header">
    <h:form>
        <p:toolbar>
            <p:toolbarGroup>
                <!-- Operaciones de aplicación -->
                <c:forEach items="#{logedBean._apps}" var="opBean">
                    <!-- MAIN OPERATION -->
                    <h:panelGroup rendered="#{opBean._Clickable}">
                        <p:commandButton value="#{opBean._Nombre}"
                            action="#{opBean.actionOperationClick}" update=":linkPanel" />
                    </h:panelGroup>
                    <!-- OPERATION WITH SUBOPERATIONS -->
                    <h:panelGroup rendered="#{!opBean._Clickable}">
                        <p:menuButton value="#{opBean._Nombre}">
                            <c:forEach items="#{opBean._subOperaciones}" var="opBean2">
                                <p:menuitem value="#{opBean2._Nombre}"
                                    action="#{opBean2.actionOperationClick}" update=":linkPanel" />
                            </c:forEach>
                        </p:menuButton>
                    </h:panelGroup>
                </c:forEach>
            </p:toolbarGroup>
        </p:toolbar>
    </h:form>
</h:panelGroup>
 

已编辑

它必须带有jsp标记,因为 Primefaces工具栏不会具有要集成到支持Bean中的特定模型,以便在页面呈现期间进行构建.因此,它必须在页面构建中. Primefaces TabView 也发生了类似的情况,但是他们设法解决了这个问题,现在tabView已经有了内置的迭代器.看看相关的提示.

https://stackoverflow.com/a/4057370/1199132

已编辑2

新的PF MenuModel似乎可以解决所有此类问题.它将能够以编程方式在Bean上构建菜单.从4.0开始可用.

http://blog.primefaces.org/?p=2594

I'm working with PrimeFaces 3.1.1 since last week and it seems to be an excellent visual component framework. I'm doing a migration from Richfaces and trying to get everything working only with Prime and JSF2 (2.1.6 version).

My problem comes with a dynamic toolbar I have to implement. Some of the operations are integrated directly on the toolbar (commandButtons) and other operations have some suboperations inside, so I have to do a menuButton with the operation name and add every single operation here like a menuitem. Here is my code:

<h:panelGroup id="Texto_Header" layout="block">
        <h:form>
            <p:toolbar>
                <p:toolbarGroup>
                    <!-- Operaciones de aplicación -->
                    <ui:repeat value="#{logedBean._apps}" var="opBean">
                            <!-- OPERACION PRINCIPAL EJECUTABLE -->
                            <h:panelGroup rendered="#{opBean._Clickable}">
                                <p:commandButton ajax="true" value="#{opBean._Nombre}"
                                    action="#{opBean.actionOperationClick}" />
                            </h:panelGroup>
                            <!-- OPERACION PRINCIPAL CON SUBOPERACIONES -->
                            <h:panelGroup rendered="#{!opBean._Clickable}">
                                <p:menuButton value="#{opBean._Nombre}">
                                    <ui:repeat value="#{opBean._subOperaciones}" var="opBean2">
                                        <p:menuitem ajax="true" value="#{opBean2._Nombre}"
                                            actionListener="#{opBean2.actionOperationClick}" />
                                    </ui:repeat>
                                </p:menuButton>
                            </h:panelGroup>
                    </ui:repeat>
                </p:toolbarGroup>
            </p:toolbar>
        </h:form>
    </h:panelGroup>

My problem is I'm getting only the first operation components, it renders the commandButtons correctly and their actions are working well, however in the case of "#{!opBean._Clickable}" I get a menuButton with the name, but no menuitem inside. It looks like the embeded ui:repeat iteration is not being well done.

I have tried the same chance using c:foreach, c:choose and c:otherwise tags and in this case I get the menus visually well done, commandButton actions are working well too, but when I click in a menuItem it's saying that opBean2 is not recognized... However as I have said before, I prefer to use JSF tags exclusively. Is there a way to do that?

解决方案

I finally managed to get it work with jsp iteration tags and changing the actionListener attributes of menuitem tags for action attributes. Here is my code:

    <h:panelGroup id="Texto_Header">
    <h:form>
        <p:toolbar>
            <p:toolbarGroup>
                <!-- Operaciones de aplicación -->
                <c:forEach items="#{logedBean._apps}" var="opBean">
                    <!-- MAIN OPERATION -->
                    <h:panelGroup rendered="#{opBean._Clickable}">
                        <p:commandButton value="#{opBean._Nombre}"
                            action="#{opBean.actionOperationClick}" update=":linkPanel" />
                    </h:panelGroup>
                    <!-- OPERATION WITH SUBOPERATIONS -->
                    <h:panelGroup rendered="#{!opBean._Clickable}">
                        <p:menuButton value="#{opBean._Nombre}">
                            <c:forEach items="#{opBean._subOperaciones}" var="opBean2">
                                <p:menuitem value="#{opBean2._Nombre}"
                                    action="#{opBean2.actionOperationClick}" update=":linkPanel" />
                            </c:forEach>
                        </p:menuButton>
                    </h:panelGroup>
                </c:forEach>
            </p:toolbarGroup>
        </p:toolbar>
    </h:form>
</h:panelGroup>

EDITED

It has to be with jsp tags because Primefaces Toolbar doesn't have specific model to be integrated in a backing bean in order to be built during page rendering. So it has to be in page build. Similar was happening with Primefaces TabView but they managed to solve it and now tabView has a built-in iterator. Take a look to a related cuestion.

https://stackoverflow.com/a/4057370/1199132

EDITED 2

New PF MenuModel seems to solve this kind of issue at all. It will be able to build the menu programatically at the bean. Available from 4.0.

http://blog.primefaces.org/?p=2594

这篇关于如何制作Primefaces动态工具栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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