8 Replies Latest reply on Jan 18, 2008 12:31 PM by Yogesh

    Menu Item With Tomahawk Action Listener

    Jane A Newbie

      Hi,
      I am trying to implement a Right Click Contextual Menu on commandLink which uses tomahawk update Action Listener. The menu items itself should be using the tomahawk update action listener to update a property in a SFSB.

      The command Link is found within a tomahawk Tree component

      My example is as follows:

       <h:commandLink value="Delete" action="#{myBean.setValue}">
       <t:updateActionListener property="#{myBean.selectedValue}" value="#{node.value}" />
      
      
       <rich:contextMenu id="GuidelineContextMenu_#{node.value.Id}" event="oncontextmenu" attached="true" submitMode="server"
       >
      
       <rich:menuItem id="GuidelineMenu_MenuItemDelete#{node.value.Id}"
      immediate="true" value="Delete" action="#{myBean.deleteValue}" >
      
       <f:facet name="icon">
       <h:graphicImage value="/images/delete1.gif" border="0" title="Delete" />
       </f:facet>
      
       <t:updateActionListener property="#{myBean.selectedValue}" value="#{node.value}" />
      
       </rich:menuItem>
       </rich:contextMenu>
      
      
      
       </h:commandLink>
      
      
      



      For example to delete a node in the Tree, the user has to right click on the command Link, the contextual menu appears and clicking on the menu item will unbind the chosen value to the property in the SFSB and then trigger the action specified in the menu item.


      I am using submitMode="server"


      My problem is that I get a "hazardous behaviour" such that sometimes the action is not triggered and othertimes my tree node values disappear.


      Is there any alternative approach for this ? Is the tomahawk update action listener component compatible with the rich menu item ?

      Any guidance on how to achieve this would be highly appreciated.


      Regards,
      Yogesh





        • 1. Re: Menu Item With Tomahawk Action Listener
          Sergey Smirnov Master

          Using JSF EL in the id looks very strange. Are you sure you have a problem with t:updateActionListener only?

          • 2. Re: Menu Item With Tomahawk Action Listener
            Jane A Newbie

            I am using JSF EL in the id because i was getting a

             duplicate Id for component error ...
            



            Using unique ids fixed this issue.

            • 3. Re: Menu Item With Tomahawk Action Listener
              Sergey Smirnov Master

              In JSF, the id of the command component on the second phase of JSF life cycle should be equal to the id assigned to the same component during the creating the component tree the previous life cycle. If not, the component will not processed. This is a general rule. No any specific with RichFaces. I doubt that the way you try to make id unique just break this rule.
              It is not clean does the bug in the JSF implementation or in your own code causes this problem. So, no any further suggestion yet.

              • 4. Re: Menu Item With Tomahawk Action Listener
                Yogesh Novice

                Thnx for the precision.

                Any idea how I could implement what i described above. Will the a4j:action param be helpful in this ?

                Regards,
                Yogesh

                • 5. Re: Menu Item With Tomahawk Action Listener
                  Sergey Smirnov Master

                  I am not sure it is about updateActionListener specifically.

                  Try to replace temporary this code with just:

                  <h:commandLink value="Text" id="link_#{node.value.Id}" action="#{myBean.myaction}"/>

                  and does the action method is invoked.



                  • 6. Re: Menu Item With Tomahawk Action Listener
                    Jane A Newbie

                    Some new findings !!

                    I am just trying this sample.

                    
                    <rich:panel>
                     <h:commandLink value="#{guidelineHierarchyBean.demoPageView.page.pageName}" action="#{guidelineEditorBean.deletePage}">
                     <t:updateActionListener property="#{guidelineEditorBean.selectedPageView}" value="#{guidelineHierarchyBean.demoPageView}" />
                     <rich:contextMenu id="GuidelineContextMenu_#{demoPageView.page.pageId}" event="oncontextmenu" attached="true" submitMode="server">
                     <rich:menuItem id="GuidelineMenu_MenuItemDelete#{demoPageView.page.pageId}">
                     immediate="true" value="Delete"
                     action="#{guidelineEditorBean.deletePage}">
                    
                     <t:updateActionListener
                     property="#{guidelineEditorBean.selectedPageView}"
                     value="#{guidelineHierarchyBean.demoPageView}"
                     />
                    
                     </rich:menuItem>
                    
                     </rich:contextMenu>
                    
                     </h:commandLink>
                    </rich:panel>
                    



                    I am able to right click, and then click on the delete menu item. The demoPageView object is the first item in the treenode.

                    For my test, I have added three demoPageViews in the treeNode

                    So in my page:

                    
                    Page 1 ---> which is the demoPageView (first item in treenode)
                    
                    
                    
                    Page 1
                    Page 2
                    Page 3 -----------> which are items in my treenode
                    
                    



                    On clicking delete, the demoPageView Page 1 is correctly deleted as follows:


                    
                    Page 2 ---> which is the demoPageView (new first item in treenode)
                    
                    
                    
                    
                    Page 2
                    Page 3 -----------> which are remaining items in my treenode
                    
                    



                    I then just refreshed my page (pressing F5) and strangely, the Page2 got deleted again.


                    
                    Page 3 ---> which is the demoPageView (new first item in treenode)
                    
                    
                    
                    Page 3 -----------> which are remaining items in my treenode
                    
                    



                    How can i work around this behaviour. Is the rich context menu item stable yet ?


                    • 7. Re: Menu Item With Tomahawk Action Listener
                      Nick Belaevski Master

                      Could you please provide action code?

                      • 8. Re: Menu Item With Tomahawk Action Listener
                        Yogesh Novice

                         

                        
                        @Stateful
                        @Name("guidelineEditorBean")
                        @Scope(ScopeType.SESSION)
                        @Interceptors(SeamInterceptor.class)
                        public class GuidelineEditorBean implements GuidelineEditor
                        {
                        
                        
                         public void deletePage()
                         {
                         log.debug("enter_deletePage");
                         log.debug("Deleting page #0", this.selectedPageView.getPage().getPageName());
                        
                         deleteSubPages(this.selectedPageView);
                         pageDAO.remove(this.selectedPageView.getPage());
                        
                         List<Page> pagesToReorder = guidelinePageUtils.getAllSubPagesByOrderNum(this.selectedPageView.getPage().getParentPageId(), this.selectedPageView.getPage().getOrderingNumber(), pageDAO.selectAll(), true);
                         for(Page page : pagesToReorder)
                         {
                         page.decrementOrderingNumber();
                         pageDAO.merge(page);
                         }
                        
                        
                         FacesMessages.instance().addFromResourceBundle("PageSuccessfullyDeleted");
                        
                         guidelineHierarchyBean.reInitializeTree();
                         this.selectedPageView = null;
                        
                        
                         }
                        
                         // Remaining Code
                        
                        }
                        
                        




                        Is there any other approach for implementing a right click contextual menu. I need this in a tomahawk tree node component. I have seen from the examples binding and unbinding of values through the action param component through a rich component control.


                        What is the simplest way of implementing a right click contextual menu on command links with binding and unbinding of selected values ?



                        Thnx heaps for the help

                        Yogesh