Wednesday, December 19, 2012

rich:menuItem's action not working in Liferay

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">
    <rich:menuItem lable="item1" action="#{bean.action1}" />
    <rich:menuItem lable="item2" action="#{bean.action2}" />
this is normal contextMenu in a Richfaces application,
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}" />
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();" />

    <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.



Related Posts Plugin for WordPress, Blogger...