Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jsf

jakarta-ee

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?

like image 704
BestPractices Avatar asked Mar 30 '10 16:03

BestPractices


1 Answers

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?

like image 62
BalusC Avatar answered Nov 08 '22 23:11

BalusC