Skip to main content link. Accesskey S

The useful resource for IBM Lotus Domino XPages development

Submit Search


Home > Server JavaScript > How to output custom content like print from an agent
xpageswiki.com
is maintained by 
Julian Buss.
You can hire me.

How to output custom content like print from an agent

ShowTable of Contents
HideTable 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"); 

Created by shafi on Sep 29, 2011 11:43:43 AM

thanks


Add Comment

Name:
Comments:
How to take your XPages App to the iPhone, iPad, Android: use Domino To Go!
Do you look for an XPages Workflow solution? Take YouAtNotes Workflow.