vineri, 6 martie 2015

[OmniFaces utilities (2.0)] Check if the current faces context is available


[OmniFaces utilities] The hasContext() method returns true when the current faces context is available (i.e. it is not null).

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

import org.omnifaces.util.Faces;
...
if(Faces.hasContext()){
   // ... there is a FacesContext, so do something
}

or, you will prefer:

import static org.omnifaces.util.Faces.hasContext;
...
if(hasContext()){
   // ... there is a FacesContext, so do something
}

I like this method because is a very nice shortcut for:

FacesContext fc = FacesContext.getCurrentInstance();
if(fc != null){
   // ... there is a FacesContext, so do something
}

Niciun comentariu:

Trimiteți un comentariu