4

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?

Aritz
  • 30,971
  • 16
  • 136
  • 217

2 Answers2

5

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

Community
  • 1
  • 1
Aritz
  • 30,971
  • 16
  • 136
  • 217
0

I think this is related to nested ui:repeat elements. I've also encountered a similar issue before by nesting them and didn't figure out how to get ui:repeat work correctly.

Currently I'm using Richfaces a4j:repeat for this issue. I haven't seen any incidents of using the UI components of Primefaces with a4j elements.

Thor
  • 6,607
  • 13
  • 62
  • 96