Home > Notes & XPages > XPages: Set headers

XPages: Set headers

Because today is Tuesday, there’s another advice:

You have the possiblity to set meta-headers in XPages. To do so, you have two possiblities.
1. In the properties of the XPage, you can add a ressource with the type metaData (see it on this picture)
2. Add a few lines of code to your BeforeRenderResponse event, like this:

try {
   var response = facesContext.getExternalContext().getResponse();
   response.setHeader("Expires", -1);
   response.setHeader("Cache-Control", "no-cache");
   response.setHeader("IE=EmulateIE7", "X-UA-Compatible");
} catch (e) {}

Propably, you would think it wouldnÄt matter where to do this, but remember, we are dealing with XPages…

Some headers can’t be set with the first method. I don’t know exactly at which point they are rendered, but sometimes, they are alrady there.

That means, when you want to add the header IE=EmulateIE7, which was described as a workaround in a former post by me, you should do this via the scond method in the BeforeRenderResponse. Else, you receive a browser warning, that this header will be ignored, because the doctype was already set. If you add it in the event, everything works fine and the header is rendered.

The funny thing is, there header is rendered with the first method, anyway, but he gets ignored because he seems to be set too late.

  1. 11/01/2013 at 2:57 pm

    Great tip.
    NB: I had to put quotes around the -1 for it to work though as setHeader expects string,string
    response.setHeader(“Expires”, “-1”);
    I also set cache-control to no-cache,no-store
    response.setHeader(“Cache-Control”, “no-cache, no-store”);

  2. 23/01/2016 at 1:55 pm

    Moin, ein feiner Artikel. Wir haben für unsere Kiddies manche Fieberthermometer restlos bereit…
    Eines mit dem man rektal erfassen kann u. 1 anderes zum
    erfassen im Gehör! Dies eignet sich gerade fein, falls man die Temperatur mühelos kurz nachmessen will – Auch
    wenn sie schlafen. Hierfür ist es vollkommen ausreichend & misst unserer Bewertung
    nach auch sehr schön.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: