I have attached f:parameter tag to component h:commandButton as follows:
<h:commandButton id="commandBtn" value="Reserve" action="#{avlbleTrucksBean.storeData}">
<f:param name="currentId" value="#{String.valueOf(truck.theIndex)}"></f:param>
</h:commandButton>
Yes, truck.theIndex is an integer.
I desire to get the value of param and use it in the managed bean, but I am not able to get the value!
The managed bean is as follows:
@ManagedBean
@SessionScoped
@Named("avlbleTrucksBean")
public class AvlbleTrucksBean implements Serializable {
private int currentId;
// getter and setter methods
public int getCurrentId() {
return currentId;
}
public void setCurrentId(int currentId) {
this.currentId = currentId;
}
public String storeData() {
FacesContext fContext = FacesContext.getCurrentInstance();
this.currentId = Integer.parseInt(getCurrentIdParam(fContext));
System.out.println("currentId is: " + currentId); // This doesn't print the value! Why?
}
// Get value from "f:param"
public String getCurrentIdParam(FacesContext fc){
Map<String,String> param = fc.getExternalContext().getRequestParameterMap();
return param.get("currentId");
}
}