wissel.net

Usability - Productivity - Business - The web - Singapore & Twins

Rendering your own output in XPages revisited


My blog post Web Agents XPages style proves to be particularity popular with a lot of questions coming in. There are a few clarifications that I'd like to share:
  • You can have one: either the Writer (for text) or the Stream (for binary content - sample here). You actually might want to opt for the stream even for textual content depending how you create it (see below)
  • You call the faceContext.getResponseWriter() in the afterRenderResponse event, while you call the facesContext.getOutputStream() in the beforeRenderResponse event (remember only one please!)
  • It seems you don't need the writer.close(); at the end. Starting with 8.5.2 this actually throws an error
  • A smart way to render output is actually a Java bean that takes a stream as a parameter. Such a bean can be fully tested and debugged outside the XPages context
  • Very often the use of your own content is to output XML or HTML or a combination of both. In LotusScript you simply use Print, so the temptation is rather high to use writer.write("..."). This misses an opportunity to take advantage of code other people have written and debugged. Let a SAX Transformer take care of encoding, name spaces and attribute handling. Use this sample as a starting point (yes SAX can be used to create a document - use a Stack to control nesting). If you have a complicated result you could use a DOM object to render your result which has the advantage that you can assemble it in a non-linear fashion
  • You can easily add an XSLT transformation to the output. This increases flexibility but costs performance, so it is a good idea to keep the Stylesheets precompiled in an application bean.
  • When you need to output XML from 2 different name spaces (e.g. XML and HTML) you can either use SAX's name space feature or you add the HTML in text sections. SAX takes care of encoding and add CDATA staements
As usual YMMV (and let me know how it goes). Other posts on rendering your own output in XPages:

Posted by on 09 December 2010 | Comments (0) | categories: XPages

Comments

  1. No comments yet, be the first to comment