0

I'm using Richfaces 3.3.3

Is it somehow possible to reRender a contextmenu and after it is rerendered, display it?

Currently I use a4j:support with the event onmouseover to reRender the contextmenu according to some values attached to the pointed component.

When the user then clicks using the right mouse button, I display the contextmenu using rich:componentControl.

I'd like to do something like this.

<a4j:support event="oncontextmenu" reRender="contextMenu" oncomplete="#{rich:component('contextmenu')}.show()">
    <a4j:actionparam ...../>
</a4j:support>
gadeynebram
  • 725
  • 2
  • 6
  • 22

1 Answers1

2

This is a trick that you can use to do that. However reRendering the whole rich:contextMenu component will not be very useful because when you do reRendering, it gets disappeared. However you can reRender each item in the menu. It will not hide the contextMenu. This is how you can do it.
Note that the div with id "my_div" is the component inside which you should right click.

<h:form id="frm" style="border:solid red; height:500px;width:500px;">
    <s:div id="my_div" style="border:solid; height:200px;width:200px;">
        Right click inside of me.
    </s:div>

    <rich:contextMenu target="my_div" submitMode="client" showEvent="click"
                  id="contextMenu" >
        <rich:menuItem value="Item 1" id="it1"/>
        <rich:menuItem value="Item 2" id="it2"/>
    </rich:contextMenu>

    <a4j:jsFunction ajaxSingle="true" name="showContextMenu" id="jsFunc"
            reRender="it1,it2" />
</h:form>

Add <script> tags within the <head> tags and put this JS.

<script>
    function validateComponent() {
        showContextMenu();
    }
    window.onload = function() {
        #{rich:element('my_div')}.oncontextmenu = validateComponent;
    }
</script>

prageeth
  • 7,159
  • 7
  • 44
  • 72
  • Hi, Thanks for your answer! It looks promising. However I cannot use it completely because my situation is a little different. I have multiple divs than can be clicked and their id's are unique but dynamicaly called. I'll try to apply your example. My first attempt failed, the contextmenu does show up but the content is not reRendered, I've now used the menu item ids to reRender. – gadeynebram Nov 08 '12 at 13:32
  • No matter whether you have extra DIVs. You may change the code accordingly. However if you still don't have any success please post your simplified code so I can find whether I could help you. – prageeth Nov 09 '12 at 03:55