[OmniFaces utilities] The
isFacesAjaxRequest()
method returns true
if the given HTTP servlet request is a JSF ajax request. This does exactly the same as Faces#isAjaxRequest()
, but then without the need for a FacesContext
. The major advantage is that you can perform the job inside a servlet filter, where the FacesContext
is normally not available.Method:
Usage:
·
inside a servlet filter or even a plain
vanilla servlet (basically, when FacesContext is not available):
import
org.omnifaces.util.Servlets;
...
@WebServlet("/MyServlet")
public class
MyServlet extends HttpServlet {
protected void
processRequest(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
// e.g.
false
boolean isFacesAjaxRequest = Servlets.isFacesAjaxRequest(request);
}
...
}
·
in JSF, when FacesContext is
available use, Faces#isAjaxRequest(), or more clumsy (not recommended):
...
// or simply
use, Faces#getRequest()
FacesContext
context = FacesContext.getCurrentInstance();
ExternalContext
externalContext = context.getExternalContext();
HttpServletRequest
request = (HttpServletRequest) externalContext.getRequest();
boolean isFacesAjaxRequest =
Servlets.isFacesAjaxRequest(request);
Niciun comentariu :
Trimiteți un comentariu