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?
精彩评论