KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
My validator needs to know if it is a full request or an ajax request. In my current solution I check the http request header for the X-Requested-With element: public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { HttpServletRequest req = (HttpServletRequest) context.getExternalContext().getRequest(); if (req.getHeader("X-Requested-With") != null) { // do something } else { // do something else } ... } Is there a better approach to achieve this? Is my solution "safe" with respect to different browsers / javascript libs? UPDATE: Just found out that the X-Requested-With header is only present if the ajax request comes from the Primefaces component library (the <p:ajax> tag). It is not present if I use plain JSF <f:ajax> . So my approach won't work with <f:ajax> . Using <f:ajax> there is a different header: Faces-Request:partial/ajax The solution proposed by Osw works for <f:ajax> and <p:ajax> : PartialViewContext#isAjaxRequest()
Tags (comma-separated)
Save Edits
Cancel