you should inject FacesContext in your java code with annotation
@In(required = true)
private FacesContext facesContext;
and your import should be :
import javax.faces.context.FacesContext;
if it is not work you should findout what is your problem and often with create new facesContext solve this problem
FacesContext facesContext = new FacesContext();