nablex
nablex

Reputation: 4757

f:ajax listener not executed because of rendered="false"?

I have a commandLink which has a "rendered" which is calculated based on values in a @RequestScoped bean. The commandLink uses f:ajax to call a listener but it appears that the method is never executed.

It turns out if I set rendered="#{true}" or no rendered attribute at all, the listener is executed properly. Is it possible that because the rendered is based on request scoped values which no longer exist at the time of the ajax postback (and hence result in a 'false'), that the listener is being skipped? Note that the f:ajax also performs a few execute actions which are performed successfully.

Upvotes: 0

Views: 337

Answers (1)

Zólyomi István
Zólyomi István

Reputation: 2441

You should never use a request scoped bean to define the value of a rendered attribute of any UI component. Unless you take special care, the original bean is destroyed losing its values, a new one is created instead with each request. Thus the component will be hidden as the rendered attribute value is most probably not evaluated to true for the next request.

You should use the view scope instead for your bean. See an example here, but you should easily find other examples searching for something like 'jsf rendered attribute request scope bean'.

Upvotes: 2

Related Questions