Xavier Dury
Xavier Dury

Reputation: 1571

What is the purpose of rendered attribute on f:viewAction?

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?

Upvotes: 2

Views: 626

Answers (1)

kolossus
kolossus

Reputation: 20691

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:

Upvotes: 1

Related Questions