dominoGuru.com
Your Development & Design Resource
Changing XPage Content-Type via Query String Parameter
07/13/2010 01:23:00 PM by Chris Toohey
Here's a simple trick that you can use to conditionally set the rendered Content-Type of a given XPage via Query String Parameter. By default, XPages render as text/html. With this simple change to your XPage Source, well, you'll be able to change that to text/plain or something like application/ms-excel!
Simply add the following to your XPage via the Source Panel:
<xp:this.afterRenderResponse>
<![CDATA[#{javascript:var ct = context.getUrlParameter("content-type");
if (ct == "") {
var ct = "text/html";
}
facesContext.getExternalContext().getResponse().setContentType(ct)}]]>
</xp:this.afterRenderResponse>
With this afterRenderResponse XPage attribute added, you can now control the rendered Content-Type via a URL Query String Parameter.
text.xsp
text.xsp?content-type=text/plain
Of course, this still loads all of the Theme-generated content and Dojo libraries. To stop that, you'll want to use a non-rendered XPage like I do in my One-click Microsoft Excel (or Symphony Spreadsheets) via XPages and SSJS example.