JSF: How can I check if I am in the Restore View phase?

When a specific method is called in my managed bean, I want to know if I am in the recovery phase in the JFF Lifecycle. How can i do this?

+4
source share
1 answer

If you are already using JSF 2.0, 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, then your best resort uses the PhaseListener , which listens for PhaseId.RESTORE_VIEW , sets the / toggle / token flag in the request area during beforePhase() and removes it during afterPhase() . Let the getter bean method check its presence in the request area.

So what exactly do you need it for? I never had the need for such a functional requirement. Is the bean constructor or the annotated @PostConstruct method probably better to use such things to initialize?

+12
source

Source: https://habr.com/ru/post/1305574/


All Articles