Is it possible to disable f:event type=“preRenderView” listener on postback?

别来无恙 提交于 2019-12-17 07:26:46

问题


Is it possible to "disable" triggering of this action when doing postback?

<f:metadata>
    <f:event listener="#{defaultNewQuestionHandler.init}" type="preRenderView" />
</f:metadata>

回答1:


That's not possible with <f:event>. You need to manually check FacesContext#isPostback() inside the listener method.

public void init() {
    if (!FacesContext.getCurrentInstance().isPostback()) {
        // ...
    }
}

In the upcoming JSF 2.2 <f:viewAction> tag, which is supposed to replace this <f:event type="preRenderView"> "workaround", it will however be possible with the onPostback attribute:

<f:viewAction action="#{defaultNewQuestionHandler.init}" onPostback="false" />

Snapshot releases of JSF 2.2 are already available.

See also:

  • What's new in JSF 2.2?


来源:https://stackoverflow.com/questions/8506033/is-it-possible-to-disable-fevent-type-prerenderview-listener-on-postback

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