Context Menu with Rich Component Control
jbossja Jan 21, 2008 2:52 AMI have been trying to implement a Right Click Contextual Menu for the past two weeks. I seem to get a bit closer now. I would like any help or comments
Requirements
= = = = = = =
- Menu is triggered on Right Clicking command Links which are tree node items (i am using tomahawk tree node component)
- The Levels in the menu is not fixed
- Ability to unbind selected objects into a SFSB
First Approach
= = = = = = =
From the examples, I tried a simple implementation of the right click contextual menu which seemed to suite my needs and also would have solved my problem quickly.
I was hoping that the t:updateActionListener would behave just as it did with h:commandLinks.
<h:commandLink .... >
<rich:contextMenu event="oncontextmenu" attached="true" submitMode="none">
<rich:menuItem value="Add">
<t:updateActionListener property="#{myBean.selectedValue}" value="{view}"/>
</rich:menuItem>
</rich:contextMenu>
</h:commandLink>
This one led to a hazardous behaviour with tree node items disappearing randomly and some actions not triggered as it should.
Second Approach
= = = = = = = =
I am trying with the second example given.
<rich:contextMenu event="oncontextmenu" attached="false" id="menu" submitMode="server" rendered="#{guidelineEditorBean.displayProperties.viewMode}">
<rich:menuItem ajaxSingle="true" value="Edit" action="#{guidelineEditorBean.editPage}">
<a4j:actionparam name="pageEdit" assignTo="#{guidelineEditorBean.selectedPageId}" value="{selectedPageView}"/>
</rich:menuItem>
<rich:menuItem ajaxSingle="true" value="Delete {selectedPageView}" action="#{guidelineEditorBean.deletePage}">
<a4j:actionparam name="pageDelete" assignTo="#{guidelineEditorBean.selectedPageId}" value="{selectedPageView}"/>
</rich:menuItem>
<rich:menuGroup value="Add" rendered="#{guidelineEditorBean.pageViewToPaste == null}">
<rich:menuItem ajaxSingle="true" value="Above" action="#{guidelineEditorBean.addPageAbove}">
<a4j:actionparam name="pageAbove" assignTo="#{guidelineEditorBean.selectedPageId}" value="{selectedPageView}"/>
</rich:menuItem>
<rich:menuItem ajaxSingle="true" value="Below" action="#{guidelineEditorBean.addPageBelow}">
<a4j:actionparam name="pageBelow" assignTo="#{guidelineEditorBean.selectedPageId}" value="{selectedPageView}"/>
</rich:menuItem>
<rich:menuItem ajaxSingle="true" value="Sub" action="#{guidelineEditorBean.addSubPage}">
<a4j:actionparam name="pageSub" assignTo="#{guidelineEditorBean.selectedPageId}" value="{selectedPageView}"/>
</rich:menuItem>
</rich:menuGroup>
</rich:contextMenu>
<rich:dataTable var="pageView" value="#{guidelineHierarchyBean.allPageViews}">
<rich:column>
<h:commandLink value="#{pageView.page.pageName}"
rendered="#{guidelineEditorBean.displayProperties.viewMode}"
>
<rich:componentControl rendered="#{guidelineEditorBean.displayProperties.viewMode}"
event="onmouseover" for="menu" operation="show">
<f:param value="#{pageView.page.pageId}" name="selectedPageView"/>
</rich:componentControl>
</h:commandLink>
<h:commandLink value="#{pageView.page.pageName}"
action="#{guidelineEditorBean.setPage}"
rendered="#{!guidelineEditorBean.displayProperties.viewMode}"
>
<t:updateActionListener property="#{guidelineEditorBean.selectedPageView}" value="#{pageView}"/>
</h:commandLink>
</rich:column>
</rich:dataTable>
This one seems to be working but my problems are:
- How do i get the right click contextual menu to be triggered on right click. There seem to be no event="oncontextmenu" for the rich component control
- The a4j:actionparam seems only to be working for String, Integer and boolean. Is there a way with which I can unbind objects to my SFSB
Thnx for any help
Regards,
Yogesh