Skip to main content link. Accesskey S

XPages Wiki

Submit Search

YouAtNotes XPages Wiki


Home > Server JavaScript > How to output custom content like print from an agent

How to output custom content like print from an agent

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

See what's possible with Xpages.
Have a look at our ServiceCommunicator website
and the YouAtNotes Support.
Use  searchlotus.com  for news in the Web related to Lotus Notes and Domino,
and to search those sites.
Check  youatnotes.com  for great Lotus Notes, Domino and XPages software.
Did this wiki help you?
Did this saved you time? Express your gratitude by making a donation:
PayPal - The safer, easier way to pay online!