I have two bean classes vehicletypes and cars from vehicletypes is a list of vehicles from which one typename is to be selected for cars class.So i am populating the list in car.xhtml by v.name its working fine using combo box.For assigning this typename to cars.name i am using listerner action as shown:
.XHTML Code
<h:selectOneMenu>
<f:selectItems value="#{vehicletypes.veh}" var="v" itemLabel="#{v.name}" />
<f:ajax event="change" listener="#{cars.combochange}" />
<f:param name="idx" value="#{v.name}" />
</h:selectOneMenu>
Managed bean:
public String getcombochange(FacesContext fc)
{
Map<String,String> params =fc.getExternalContext().getRequestParameterMap();
return params.get("idx");
}
public String combochange(){
String type;
FacesContext fc = FacesContext.getCurrentInstance();
type= getcombochange(fc);
System.out.println("\nChange occured Car type assigned"+type);
return "result";
}
While printing the value of cartype on console using println it always null,Whats wrong in the code i tried to pass a defualt string as param but its also not working.
Have tried this way as well but this doesn't call the action itself;
.xhtml
<h:selectOneMenu>
<f:selectItems value="#{vehicletypes.veh}" var="v" itemLabel="#{v.name}" />
<f:ajax event="change" listener="#{cars.combochange}" />
<f:attribute name="add" value="default" />
</h:selectOneMenu>
Bean Class
public String combochange(ActionEvent event){
String type = (String)event.getComponent().getAttributes().get("add");
System.out.println("Add pool:"+type);
return null;
}
Dont understand why the action is not called.