How to create a dynamic toolbar

I've been working with PrimeFaces 3.1.1 since last week and it seems to be a great visual component framework. I'm making a switch from Richfaces and trying to get everything to work with Prime and JSF2 only (version 2.1.6).

My problem is with a dynamic toolbar that I have to implement. Some of the operations are integrated directly into the toolbar (commandButtons) and other operations have some sub-operations inside, so I have to make a menuButton with the name of the operation and add each operation here as a menu item. 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 only get the first operational components, it displays the commandButtons correctly and their actions work well, however in the case of "# {! OpBean._Clickable}" I get a named menuButton but not inside. It looks like inline ui: re-iteration is not well done.

I tried the same possibility using c: foreach, c: select and c: otherwise tags and in this case I render the menu visually well, the commandButton actions work well too, but when I click on the menuItem it says that opBean2 is not recognized ... As I said, I prefer to use only JSF tags. Is there a way to do this?

+3


source to share


2 answers


I finally managed to get it to work with jsp iteration tags and change the actionListener attributes of the menuitem tags for the 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 must be tagged with jsp because the Primefaces toolbar does not have a specific model to integrate into the fallback bean in order to be created during page rendering. So this should be in the page creation. A similar thing happened with Primefaces TabView , but they managed to solve the problem and now the tabView has a built-in iterator. Take a look at the related question.



fooobar.com/questions/746498 / ...

EDITED 2

The new PF MenuModel seems to solve this problem altogether. He will be able to program the menu using a bean. Available from 4.0.

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

+4


source


I think it has something to do with nested elements ui:repeat

. I also ran into a similar problem before, attaching them and didn't figure out how to get it right ui:repeat

.



I am currently using Richfaces a4j:repeat

for this problem. I have not seen any use cases of Primefaces interface components with elements a4j

.

0


source







All Articles