ShowTable of Contents
You can use server side javascript in a XPage to write custom content to the browser, just like with agents and "print" statements in classic web development.
This tip is taken from Stephan Wissel from http://www.wissel.net/blog/d6plinks/SHWL-7MGFBN
.
- create a Xpage
- set the "rendered" property of the XPage (!) to false (so that NOTHING of the Xpage is rendered)
- in afterRenderResponse event write some code like this:
// The external context gives access to the servlet environment
var exCon = facesContext.getExternalContext();
// The writer is the closest you get to a PRINT statement
// If you need to output binary data, use the stream instead
var writer = facesContext.getResponseWriter();
// The servlet's response, check the J2EE documentation what you can do
var response = exCon.getResponse();
// In this example we want to deliver xml and make sure it doesn't get cached
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
// Here all your output will be written
writer.write("<?xml version="1.0" encoding="UTF-8"?>n<christmas date"24Dec" />");
// We tell the writer we are through
writer.endDocument();
facesContext.responseComplete();
Control browser caching
Forbid caching:
response.setHeader("Cache-Control", "no-cache");
Let the browser cache your content until an expire date:
var now = new Date();
response.setDateHeader("Expires", now.getTime() + (30*24*60*60*1000));
response.setHeader("Cache-Control", "public");