Distinguish ajax requests from full requests in JSF custom validator
问题 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