Distinguish ajax requests from full requests in JSF custom validator

后端 未结 2 1596
北海茫月
北海茫月 2021-02-20 05:27

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:

2条回答
  •  执笔经年
    2021-02-20 05:53

    I would not rely on http header. Never tried it by myself, but you could do the following:

    PartialViewContext pvc = facesContext.getPartialViewContext();
    if(pvc.isAjaxRequest()) {
    // ...
    } else {
    // ...
    }
    

    Another option is using isPartialRequest() instead of isAjaxRequest()

提交回复
热议问题