2 Replies Latest reply on Mar 26, 2008 9:20 PM by pdpantages

    Putting oncontextmenu in datatable row tags

    pdpantages

      Hello Forum,

      I am using richfaces 3.1.4.GA

      I want to use the oncontextmenu event in rich:datatable objects.

      I took a look at the source, and found the small table in AbstractRowsRenderer.java. It looks like I can just switch the mapped event for "onRowMouseDown" to render an "oncontextmenu" instead of the normal "onmousedown".

      I understand that this would make the normal usage of onRowMouseDown unavailable, but I am willing to live with this, as I am not using it. After my one-line change, the table looks like so:

      public static final String[][] TABLE_EVENT_ATTRS = {
       {"onclick","onRowClick"},
       {"ondblclick","onRowDblClick"},
       {"onmousemove","onRowMouseMove"},
       {"onmouseup","onRowMouseUp"},
       {"oncontextmenu","onRowMouseDown"},
       {"onmouseover","onRowMouseOver"},
       {"onmouseout","onRowMouseOut"}
       };
      


      I followed the instructions from the wiki and built it. It seems to work as expected; I specify onRowMouseDown, it renders "oncontextmenu" in my table rows. The resulting context menu works properly.

      My question, is, am I going to be able to get away with this....?
      I am not at all familiar with richfaces source, but it looks to me like it should be ok. I am worried that I might cause some obscure problems (e.g., memory leaks?) or worse....

      PdP

        • 1. Re: Putting oncontextmenu in datatable row tags
          nbelaevski

          Hello,

          We've already got request for similar feature: http://jira.jboss.com/jira/browse/RF-2170

          Context menu event is a bubbling one, so why not use wrapper div with event handler declared on it instead of table?

          • 2. Re: Putting oncontextmenu in datatable row tags
            pdpantages

            Hello Nick, thank you for the info. I can't seem to get anything to work. I tried the div wrapper as you suggest, but my menu does not work. It this what you were suggesting (below)?

            Btw do you think my mods to AbstractRowsRenderer.java would cause any problems?

            I need the component control to pass me some row-specific parameters, so I have to keep this component inside the dataTable tag, and set the attachTo to the div.

            I think I really need to attach to the row, no?

            This is what I tried:

            <div id="cdiv">
            
             <rich:dataTable
             rowClasses="alarmRowOdd, alarmRowEven"
             value="#{nodeList}"
             onRowClick="fselect('#{networkElement.id}', ctrlkey )"
             var="networkElement"
             rendered="true" >
            
             <c:forEach items="#{nodeRowFormats.columnDataModel}" var="column">
            
             <rich:column sortable="false">
             .... etc.
             </rich:column>
            
             </c:forEach>
            
             <rich:componentControl event="oncontextmenu" attachTo="cdiv" for="menu" operation="show">
             <f:param value="#{networkElement.id}" name="neId"/>
             <f:param value="#{networkElement.name}" name="name"/>
             <f:param value="/img/ne16.png" name="icon"/>
             </rich:componentControl>
            
             </rich:dataTable>
            
            </div>