0

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.

nablex
  • 4,635
  • 4
  • 36
  • 51
  • 1
    Related: http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked/2120183#2120183 (point 5) – BalusC Dec 03 '12 at 12:03

1 Answers1

2

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'.

Community
  • 1
  • 1
Zólyomi István
  • 2,401
  • 17
  • 28
  • The thing is that when performing the postback nothing is rerendered so one would assume the "rendered" attribute does not have any impact at that point. But apparantly it does for listener execution, though not for value submission. This seems odd to me. – nablex Dec 03 '12 at 09:53
  • The behavior is really odd and unintuitive, I had very bad experiences and don't understand it myself in full depth. IMHO it's so bad that I don't even see any legitimate usage for this 'feature'. I think using a request scope with rendered should throw a 'compilation' error immediately for the whole page, similarly to a syntax error in an EL expression. As a solution I use the 'never use request scope' mantra and it efficiently keeps me out of trouble. Maybe @BalusC should explain the reasons or add a better link here. – Zólyomi István Dec 03 '12 at 14:42