I have a h:commandButton on a jsf page. And it needs to be rendered based on a condition. The property on the condition is a hidden input to the page. The action method on the button is not called when the rendering condition is specified.
Any ideas?
here is the sample code:
<h:commandButton value="Button"
action="#{bean.method}"
rendered="#{bean.conditon}"
type="submit"/>
<h:inputHidden value="#{bean.condition}" />
I understand that your bean is request scoped, otherwise you wouldn’t have this problem. This is a timing problem.
The
renderedattribute is also determined during “apply request values” phase of JSF lifecycle. However, the submitted values are only been set in the model during “update model values” phase of JSF lifecycle, which is later. Thus, whenrenderedattribute is evaluated, it doesn’t get the submitted value from the hidden input, but instead the property’s default value.If it’s not an option to change the request scope to the view scope, then you’d need to salvage this problem differently. One of the simplest ways changing the
<h:inputHidden>to be a<f:param>and inject the value via@ManagedPropertyon#{param}map:(note that I omitted
type="submit"as it’s the default already)with
See also: