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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With