action method is not called Please refer to this question – , One of my UICommand Component is rendered conditionally , it was said in the answer of the linked question – point 5 – that if the Component’s or any of its parents rendered or disabled attributes are false – then the action method will not be called ? If thats the case- How do i achieve the same functionality? Is there a work around ? or a trick ? or any other approach ?
Thanks!
To the point, you’d like to retain the property responsible for the
renderedcondition in the subsequent request. There are several solutions for this problem:Put bean in session scope. It’s easy, but it hurts. It’s bad for user experience since changes will be reflected in all tabs/windows the user has open in the same session.
Use
<h:inputHidden>to transfer the property. In theory easy, but in practice it hurts as well. The value will namely get lost whenever a validation/conversion error has occurred in any of other inputs in the same form. This is an odditity in how JSF handles hidden input elements. A workaround is to use<h:inputHidden binding="#{bean.hidden}">and do ahidden.getValue()andhidden.setValue()in bean.If you’re using
<h:commandLink>instead of<h:commandButton>, then you can use<f:param>to transfer the property. It will be available as request parameter, you can check for it in bean’s (post)constructor.Use Tomahawk’s
<t:saveState>. The perfect solution as far. This will retain the value (or even a complete bean) in the subsequent request.If you’re already on JSF 2.0, the
@ViewScopedwould have solved this all. It behaves like the<t:saveState>.See also: