Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6573051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:05:00+00:00 2026-05-25T15:05:00+00:00

My validator needs to know if it is a full request or an ajax

  • 0

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()

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:05:00+00:00Added an answer on May 25, 2026 at 3:05 pm

    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()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First thing: I know that there is interface to W3C validator: http://pear.php.net/package/Services_W3C_HTMLValidator/ But I
I need to know if all the client-side validator checks have succeeded, or if
Why Microsoft.Practices.ServiceLocation.IServiceLocator does not offer TryGetInstance()? I need to get generic validator instance ServiceLocator.Current.GetInstance<IEntityValidator<TEntity>>()
I know W3C Validator can do this but i need any free offline editor.
Does anyone know how to disable an ASP.NET validator using JavaScript? I'm using javascript
I need to know how the performance of different XML tools (parsers, validators, XPath
i have two dates ValidFrom : 20-04-2010 validTo : 02-05-2010 i need to know
I have a e-mail address validator but I need to add special characters as
I need to validate the email address of my users. Unfortunately, making a validator
I need to validate an XML agaist a schema. I tried XML::SAX::ParserFactory; XML::Validator::Schema and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.