luni, 9 martie 2015

[OmniFaces utilities (2.0)] Shortcut for getting the current phase ID


[OmniFaces utilities] The getCurrentPhaseId() method returns the current phase ID.

Method:
See also: Faces#getContext()
Usage:

This method is a simple shorcut for:

FacesContext fc = FacesContext.getCurrentInstance();
PhaseId phaseid = fc.getCurrentPhaseId();

So, you can use it like this:

import org.omnifaces.util.Faces;
import javax.faces.event.PhaseId;
...
PhaseId phaseid = Faces.getCurrentPhaseId();

or,

import static org.omnifaces.util.Faces.getCurrentPhaseId;
import javax.faces.event.PhaseId;
...
PhaseId phaseid = getCurrentPhaseId();

For example, you can used this to check if the current phase correspond with the expected phase (e.g. check if the current phase is APPLY_REQUEST_VALUES):

if(phaseid.equals(PhaseId.APPLY_REQUEST_VALUES)){
   // do something
} else {
   // do something else
}

Niciun comentariu:

Trimiteți un comentariu