Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Richfaces: Link-like text with ContextMenu

I want to render using Richfaces a context menu on left click on a link-appearing text (blue text, and underline and cursor onmouseover). So, imagine a link which when clicked shows a context menu. Note that I don't care if the text is indeed a link, I just want it to appear as a link. So, even normal text would be fine, I would make it appear as a link using CSS.

I have the following conditions:

  • The context menu must appear on client side, without making a request.
  • The context menu must appear using a rich:componentControl (these "links") are inside a datatable, so the same rich:contextMenu must be re-used.

I still have not found a satisfactory solution, as each approach I have tried has caused a problem for me:

  1. If I use h:outputText (that would be ideal), I cannot attach on it a rich:componentControl (I guess because it cannot fire an onclick event).
  2. If I use a4j:commandLink, although I can attach a rich:componentControl, it makes a server request. I tried to add onclick="return false;" to prevent the request, but Richfaces adds the JS generated by the rich:componentControl after whatever is inside the onclick, which causes this code not to be reached at all, and of course the context menu not to appear at all.

Is there any way to do this? Please remember, no request!

like image 941
Markos Fragkakis Avatar asked Nov 06 '22 03:11

Markos Fragkakis


1 Answers

You may try

<rich:componentControl disableDefault="true" ...>

According to documentation with this param componentControl should add return false; itself.

But be aware of corresponding bug: RF-5607

In case documentation lies you may use html anchors. This answer shows how to create a link with componentControl and without page refresh:

<h:outputLink value="#" id="link" onclick="return false;">
  <h:outputText value="Link text"/> 
  <rich:componentControl attachTo="link" for="panel" operation="show" event="onclick"/>
</h:outputLink>

The onclick="return false;" prevents the anchor from scrolling the page to the clicked link.

like image 199
Vladimir Korolev Avatar answered Nov 15 '22 13:11

Vladimir Korolev