[OmniFaces utilities] The
isFacesResourceRequest()
method returns true
if the given HTTP servlet request is a JSF resource request. I.e. this request will trigger the JSF ResourceHandler
for among others CSS/JS/image resources.Method:
OmniFaces 2.4 (uses Servlets.getRequestURI()) | OmniFaces 2.0 |
Usage:
This implementation relies on the fact that a JSF request path that points a resource will contain the ResourceHandler.RESOURCE_IDENTIFIER contract:
·
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 {
boolean isFacesResourceRequest =
Servlets.isFacesResourceRequest(request);
}
...
}
·
in JSF, when FacesContext is available you can use:
import
org.omnifaces.util.Servlets;
...
// or simply
use, Faces#getRequest()
FacesContext
context = FacesContext.getCurrentInstance();
ExternalContext
externalContext = context.getExternalContext();
HttpServletRequest
request = (HttpServletRequest) externalContext.getRequest();
boolean isFacesResourceRequest =
Servlets.isFacesResourceRequest(request);
Niciun comentariu :
Trimiteți un comentariu