开发者

JSF: How can I check whether I'm in the "Restore View" phase?

开发者 https://www.devze.com 2022-12-24 22:42 出处:网络
When a particular method in my managed bean gets called, I want to know开发者_如何学编程 whether I\'m in the Restore View phase of the JSF Lifecycle. How can I do this? If you\'re already on JSF 2.0,

When a particular method in my managed bean gets called, I want to know开发者_如何学编程 whether I'm in the Restore View phase of the JSF Lifecycle. How can I do this?


If you're already on JSF 2.0, then you can check it using FacesContext#getCurrentPhaseId():

if (FacesContext.getCurrentInstance().getCurrentPhaseId() == PhaseId.RESTORE_VIEW) {
    // Restore view called.
}

But if you're still on JSF 1.x yet, then your best resort is using a PhaseListener which listens on PhaseId.RESTORE_VIEW, sets a flag/toggle/token in the request scope during beforePhase() and removes the it during afterPhase(). Let the bean's getter method check its presence in the request scope then.

That said, what exactly do you need it for? I've never had the need for such a functional requirement. Isn't the bean's constructor or an @PostConstruct annotated method probably a better place to do initialization stuff like this?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号