3 Replies Latest reply on Jul 21, 2010 7:42 AM by Ilya Shaikovsky

    Render ContextMenu Items based on condition

    Björn Meyer Newbie

      Hi,

       

      I have a tree view with a list of users. Now I want to assign a context menu, but some of the menu items should be disabled / not rendered based on a boolean condition value from the user bean. The value is passed with a f:param in rich:componentcontrol, but somehow it can't be used as a conditional value in the context menu.

       

      I found this two and a half year old thread ( http://community.jboss.org/message/34950) where someone says that you can't use such a value as a conditional value, but no real workaround is proposed.

       

      Does somebody have a solution for this?

        • 1. Re: Render ContextMenu Items based on condition
          Björn Meyer Newbie

          In another thread it was proposed to use the condition value for CSS like this as a workaround:

           

          styleClass="{var.hidden ? 'display-none' : ''}"

           

          But I couldn't get this to work. Does someone else have an idea?

          • 2. Re: Render ContextMenu Items based on condition
            Björn Meyer Newbie

            Another approach:

             

            The context menu is activated via rich:componentControl

             

            <rich:componentControl disableDefault="true" event="oncontextmenu" for="cm" operation="show">

            <f:param ... />
            </rich:componentControl>

             

            Now I'm trying to set the current item in a bean by using a4j:actionparam instead of f:param, but it seems as if you can't use an actionparam inside a rich:componentControl. Is that right?

            • 3. Re: Render ContextMenu Items based on condition
              Ilya Shaikovsky Master

              workaround with styleClass - the only I think which will work completelly on the client. I'm afraid all the other solution - to show the menu via ajax with reRendering(to draw items in new states) and calling show in oncomplete.

               

               

              Try something like that again please(actually I do not tested this yes):

               

              <menu>
              ...
              <item styleClass="{hidden? 'displayNoneClass' : '' }"
              ...
              <menu>
              
              <rich:componentControl disableDefault="true" event="oncontextmenu" for="cm" operation="show">
                   <f:param name="hidden" value="#{..some node expression which returns boolean flag for this node}"/>
              </rich:componentControl>