Markos Fragkakis
Markos Fragkakis

Reputation: 7771

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:

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!

Upvotes: 5

Views: 1062

Answers (1)

Volodymyr Korolyov
Volodymyr Korolyov

Reputation: 3067

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.

Upvotes: 2

Related Questions