wood burning stoves*
The moose likes JSF and the fly likes icefaces menuitem event handler Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSF
Bookmark "icefaces menuitem event handler" Watch "icefaces menuitem event handler" New topic
Author

icefaces menuitem event handler

Adnan Gondal
Ranch Hand

Joined: Apr 30, 2011
Posts: 32
Hello all!
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?
Thanks in advance.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16101
    
  21

If you use the "Code" button on our message editor to wrap your code and XML samples, they will be easier to read.

As for your logic, you are making things much, much too difficult.

You don't need a Listener if you have an action method. And in fact, you rarely need to code action listeners. I cannot remember when I last did so.

You also don't need all that complicated logic to get the value from the form request. JSF reads the form, validates the data and updates the backing bean's properties automatically. All you need to do in your action method is to use the properties the same way you would in non-JSF POJO code.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
GeeCON Prague 2014
 
subject: icefaces menuitem event handler