9 Replies Latest reply on Mar 14, 2008 6:04 AM by vendetta

    [ContextMenu] Render/disable menuItems depending on selected

      I have a rich:dataTable with a context menu. If the user opens the context menu I want to render/disable menu items depending on underlying bean properties (i.e. typeId) for that row.

      I have a rich:dataTable as follows:

      <rich:dataTable
       id="data"
       var="row"
       value="#{dataBean.model}">
       <h:column>
       .....
      
       <rich:componentControl event="onRowClick" for="menu" operation="show">
       <f:param value="#{row.active}" name="active"/>
       </rich:componentControl>
      </rich:dataTable>
      


      Now I've definded a <rich:contextMenu> which is associated with the table above with several <rich:menuItems> whereas "active" is a boolean property:
      <rich:contextMenu submitMode="ajax" attached="false" id="menu">
       ....
       <rich:menuItem ajaxSingle="true" value="Active" action="#{myBean.test}" rendered="{active}">
       </rich:menuItem>
      </rich:contextMenu>
      


      So far so good. Now I want to achieve, that the given menuItem is only rendered when the active boolean ist true.
      Until now I tried it with the rendered attribut in that way: rendered="#{active}" or rendered="{active}".

      Has anybody a suggestion for this problem? Is there another way for rendering/disabling different menuItems depending on the selected row in the datatable?

      Thanks in advance

        • 1. Re: [ContextMenu] Render/disable menuItems depending on sele

          I had a look on the generated HTML and JavaScript code and saw that the parameters (car and model in the richfaces examples) were set by using JavaScript. That explains why it's not possible using these kind of parameters in EL.

          I think it is a common problem to disable one or more context menu items depending on the underlying row data. One example is the Windows Explorer. If you right-click on a zip file, the context menu has a item which allows you to extract the file directly.

          Is there any possibility to render or disable menuItems depending on the row date of a rich:dataTable similiar to adapting the label/caption of an item (like richfaces examples)?

          • 2. Re: [ContextMenu] Render/disable menuItems depending on sele

            i have same problem, i want to hide the contextmenu item(s) through rendered/disable. The boolean property and the item's value come from the backing bean at the same time. but the item can not be hidden, only the content of the item.

            <rich:menuItem id="propertyItemId" value="#{ctrl.contextMenuObject.items[1]}"
             rendered="#{ctrl.contextMenuObject.isConnection}" ajaxSingle="true"
             onclick="showProperty()" />
            
            .

            another question: how create a dynamic contextmenu, must with with several <rich:menuItems> (with rendered/disable)?

            • 3. Re: [ContextMenu] Render/disable menuItems depending on sele

              The problem is: First the contextmenu shows with the items, which is rerendered with default value. For exsample: i habe defined two items in contextmenu, i want to show the second items, only the boolean parameter "showSecondItem" is true. The boolean parameter is setup by business logic. In backing bean the boolean parameter default value is "false", it shows only an item in contextmenu, even if the "showSecondItem" is assigned as "true" lately. If it assigned as "true" in backing bean, it shows two items in contextmenu, if "showSecondItem" is assigned as "false" lately, the second item is not be hidden, only the name of items is hidden.

              • 4. Re: [ContextMenu] Render/disable menuItems depending on sele
                rajshake

                I have the same question/issue. Is it possible to render/disable certain menuItems based on the row clicked ?
                Thanks in advance.

                • 5. Re: [ContextMenu] Render/disable menuItems depending on sele

                  Hi at all, I have the same problem for rendered at runtime the menuItems on the row clicked.

                  This is my code :

                  <rich:contextMenu attached="false" id="menuActionTranche"
                   submitMode="ajax">
                  
                   <a4j:support event="onexpand" reRender="azioniAdesioneMenu" />
                  
                   <rich:menuItem>
                   <b>{descrizioneTranche}</b>
                   </rich:menuItem>
                  
                   <rich:menuGroup id="azioniAdesioneMenu" value=" Azioni"
                   icon="/images/fulmine.gif">
                  
                   <rich:menuItem id="dynamicAdesioneUtente"
                   disabled="#{ManagedBeanTranchesUtente.disabled}"
                   action="#{ManagedBeanTranchesUtente.actionAdesioneUtenteTranche}"
                   oncomplete="Richfaces.showModalPanel('panelAdesioneUtente');"
                   reRender="viewAdesione" icon="/images/money.gif" eventsQueue="foo"
                   limitToList="true" ignoreDupResponses="true">
                  
                   <h:outputText value="Aderisci" />
                  
                   <f:param name="opType" value="AdesioneUtenteTranche" />
                   <f:param name="idOpvTranche" value="{idOpvTranche}" />
                   </rich:menuItem>
                  
                   </rich:menuGroup>
                  
                  </rich:contextMenu>
                  


                  I intercept the event

                  <a4j:support event="onexpand" reRender="azioniAdesioneMenu" />


                  and I reRender the menuGroup azioniAdesioneMenu, in this way the framework should reRender the menuItem dynamicAdesioneUtente.
                  But It does not work well !!!
                  I think that it is a bug ! Can someone confirm to me this ?

                  Thanks in advance

                  • 6. Re: [ContextMenu] Render/disable menuItems depending on sele

                    I have forgot to say that I use RichFaces 3.1.4

                    • 7. Re: [ContextMenu] Render/disable menuItems depending on sele

                      I use version 3.1.4. I have tried with version 3.2.0 snapshot and getted the same problem. When you define a contextmenu, at beginning the contextmenu is instanced, afterwards check the rendered/disable condition. only the condition is determined before the event="oncontextmenu". it hast the chance, the items is dynamic created.

                      • 8. Re: [ContextMenu] Render/disable menuItems depending on sele
                        fstof

                        I havent actually tred this myself.
                        But one of the rules with RichFaces is that you can not create new content. but rather replace/rerender components

                        Now when you say

                        ... id="comp1" rendered="#{active}"...

                        and #{active} is false the comonent is not rendered at all. so when you call something like

                        ...reRender="comp1"...

                        comp1 does not exist, because it was not rendered in the first place...
                        what I suggest is rather use

                        ...disabled="#{!active}"...


                        Again I have not tried this and I'm only suspecting this...

                        • 9. Re: [ContextMenu] Render/disable menuItems depending on sele

                          Hi everybody,

                          We have found this work around, rather to use contextMenu component We have used dropDownMenu compenent and rather to use disabled property on menuItem we have used rendered property on menuItem.

                          We have test this solution added a new column (example option) on our table and dropDownMenu is showed on mouse click in this option column.

                          It' s different graphical effect but It work well and so I must not added a new colums in my table for each option.

                          Best Regards