2

The description of the rendered attribute of f:viewAction is not clear in the official documentation.

I was thinking that, if it contained an expression that evaluated to false, the action expression would not be executed like in the following example:

<f:viewAction
    action="#{javax.enterprise.context.conversation.begin()}"
    rendered="#{javax.enterprise.context.conversation.isTransient()}"
/>

But the action is always executed no matter what the rendered attribute evaluates to.

So what is its purpose?

Xavier Dury
  • 1,530
  • 1
  • 16
  • 23

1 Answers1

1

You're probably a victim of the timing of the evaluation of the rendered attribute. You're safer using the if attribute of the viewAction as it's sole purpose is your use case:

     <f:viewAction action="#{javax.enterprise.context.conversation.begin()}"
if="#{javax.enterprise.context.conversation.isTransient()}"/>

The if attribute executes the view action only if it evaluates to true, and it's new with JSF2.2

Related:

Community
  • 1
  • 1
kolossus
  • 20,559
  • 3
  • 52
  • 104
  • Thanks, it works! But how could I have guessed about the `if` attribute?! Any idea why this is not documented on the link I provided? – Xavier Dury Jul 31 '14 at 06:46
  • @Xavier - My guess would be that the `if` attribute might have been a late addition to the tag, and got missed in the documentation generation process – kolossus Jul 31 '14 at 12:44