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

纵然是瞬间 提交于 2020-01-05 03:04:15

问题


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?


回答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:

  • When to use preRenderView versus viewAction?


来源:https://stackoverflow.com/questions/25037251/what-is-the-purpose-of-rendered-attribute-on-fviewaction

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!