Reputation: 4607
Following is my home page:
<h:body styleClass="ice-skin-rime">
<h:form id="form">
<ice:menuBar orientation="#{menuBar.orientation}">
<ice:menuItem value="HRM" id="hrm">
<ice:menuItem id="myPage" value="MyPage"
actionListener="#{a.listener}"
action="#{a.param}">
<f:param name="myParam" value="myPage"/>
</ice:menuItem>
</ice:menuItem>
</ice:menuBar>
</h:form>
</h:body>
Following is my bean class
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import java.util.Map;
public class a
{
private String param;
private String orientation = "horizontal";
public String getParam()
{
return param;
}
public void setParam(String param)
{
this.param = param;
}
public void listener(ActionEvent e)
{
FacesContext facesContext = FacesContext.getCurrentInstance();
Map params = facesContext.getExternalContext().getRequestParameterMap();
String myParam = (String) params.get("myParam");
if (myParam != null && myParam.length() > 0)
{
setParam(myParam);
}
else
{
setParam("not defined");
}
}
public String getOrientation()
{
return orientation;
}
public void setOrientation(String orientation)
{
this.orientation = orientation;
}
}
Can anyone please tell me how to handle action event of menu item?
Upvotes: 0
Views: 1122
Reputation: 20800
First of all it looks like you are not clear on the distinction between using the action()
vs actionListener()
. You want to use action()
when you want to return something for navigation rules. You use actionListener()
when you want to return nothing but wish to update certain components on your page.
From your code it looks like you are not planning on navigating to any other page so take out the action()
method from your ice:menuItem component.
<ice:menuItem id="myPage" value="MyPage"
actionListener="#{a.listener}" >
<f:param name="myParam" value="myPage"/>
</ice:menuItem>
I am assuming you have a
defined in your faces-config.xml
as a managed bean.
Upvotes: 1