I have a few hiden fields in my .xhtml page.
<h:inputHidden value="1" id="hidePrev"/>
.....
<h:inputHidden value="1" id="hideNext"/>
And I can’t catch their values from my JSF bean.
public class FacesUtil {
public static Object getMapValue(String key) {
return FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().get(key);
}
public static void setMapValue(String key, Object value) {
FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().put(key, value);
}
}
My bean code:
nextFlag = (String)FacesUtil.getMapValue("hideNext");
prevFlag = (String)FacesUtil.getMapValue("hidePrev");
Fields nextFlag and prevFlag are still empty. They have getter and setter methods. I’m using JSF 2.2 ver. Please, help me to resolve this problem.
The
<h:inputHidden>isn’t intented to add custom request parameters to the form submit. It’s intented to remember already-definied bean properties across postbacks. For adding custom request parameters, you should be using<f:param>in command components or “plain vanilla”<input type="hidden">instead.Thus, so
or so
Either way, the values are in a request scoped bean available as
Or in a broader scoped bean as
Please note that you confused request parameters with application scoped attributes. This is seriously a pretty major mixup which proves that you have no idea what you’re doing. I strongly recommend to take a pause and go through a basic JSF tutorial once again.