Recently I found that the richfaces contextMenu is not working properly in Liferay portal.
when I bind an action in <rich:menuItem />, the action is not being invoked.<rich:contextMenu target="editpic" mode="client" showEvent="click">this is normal contextMenu in a Richfaces application,
<rich:menuItem lable="item1" action="#{bean.action1}" />
<rich:menuItem lable="item2" action="#{bean.action2}" />
</rich:contextMenu>
But it is not working in Liferay JSF application.
Besides, I'm also found that richfaces dropdownMenu having the same problem in Liferay.
<rich:dropDownMenu label="Option1" mode="client">
<rich:menuItem label="Suboption 1-1" action="#{bean.action1}" />
<rich:menuItem label="Suboption 1-2" action="#{bean.action2}" />
<rich:menuItem label="Suboption 1-3" action="#{bean.action3}" />
</rich:dropDownMenu>
Thus, I guessed the problem is actually from <rich:menuItem /> instead of <rich:contextMenu />.
Anyway, I have overcomed this problem with <a4j:jsFunction /> with the following codes.
<rich:contextMenu target="editpic" mode="client" showEvent="click">
<rich:menuItem lable="item1" onclick="function1();" />
<rich:menuItem lable="item2" onclick="function2();" />
</rich:contextMenu>
<a4j:jsFunction name="function1" action="#{bean.action1}" />
<a4j:jsFunction name="function2" action="#{bean.action2}" />
With this approach, your menuItem is actually calling a jsFunction to invoke the managedBean action.
<rich:contextMenu target="editpic" mode="client" showEvent="click">
<rich:menuItem lable="item1" onclick="function1();" />
<rich:menuItem lable="item2" onclick="function2();" />
</rich:contextMenu>
<a4j:jsFunction name="function1" action="#{bean.action1}" />
<a4j:jsFunction name="function2" action="#{bean.action2}" />
With this approach, your menuItem is actually calling a jsFunction to invoke the managedBean action.
Done!!
Thanks for the tips. Unfortunately, richfaces menuItem action attribute is still not working for some reason.
ReplyDeleteYes, It's still not working. But at least we can work with this workaround without blocking the development.
DeleteBesides, we can also pass some parameters to the action with <a4j:jsFunction />.
Delete