2 Replies Latest reply on Apr 1, 2010 7:54 AM by Peter Len

    Dynamic menuItem changes via Javscript... possible??

    Peter Len Apprentice



      I have a rich:tree where I have defined a context menu for a rich:treeNode:


      <rich:treeNode type="opl">

           <h:outputText value="#{treedata.label}" />


           <rich:contextMenu event="oncontextmenu" submitMode="none">

              <rich:menuItem value="Edit" onclick="....."/>

              <rich:menuItem value="Copy" onclick="..."/>

              <rich:menuItem value="Paste" disabled="true" onclick="..."/>




      What I want to be able to do is be able to do si something like the following.


      1) The Paste menu item is initially disabled.

      2) When the user clicks the Copy menu item, I want to call a clientside Javascript function that will set the Paste menu item to be enabled.  This will allow the other treeNodes to have an enabled Paste context menu.


      I have tried all sorts of tests in trying to get a handle to the menuItem and/or contextMenu via javascript but nothing seems to work.  I am not sure if this is even possible or if in order to enable/disable menuItems, I must rerender the tree and have the server determine which ones should be enabled through the definition of additional treeNodes types.


      As an example of what I am trying to do through the Dojo widget library, I can define a Dojo menu with multiple menu items.  I then get access to those objects via javascript by using dijit.byId("cm_abstract_pf"); which is a special menchanism through the Dojo library to access Dojo created objects.  Then I can call mentods like setLabel() or setDisabled() on the menuItem.  I was hoping that RichFaces has a similar mechanism but it doesn't look like it does.


      Does anyone know I you can dynamically change menuItem attributes (like disabled) via Javascript?


      Thanks for any thoughts - Peter