dominoGuru.com

Your Development & Design Resource

Changing XPage Content-Type via Query String Parameter

IBM Lotus Notes Domino XPages 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

IBM Lotus Notes Domino XPage rendered as 'text/html' Content-Type

text.xsp?content-type=text/plain

IBM Lotus Notes Domino XPage rendered as 'text/plain' Content-Type

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.


About the author: Chris Toohey

Thought Leadership, Web & Mobile Application Development, Solutions Integration, Technical Writing & Mentoring

A published developer and webmaster of dominoGuru.com, Chris Toohey specializes in platform application development, solutions integration, and evangelism of platform capabilities and best practices.



More from dominoGuru.com


dominoGuru.com is powered by IBM Notes Domino XPages & hosted by Prominic.NET

Contact Us

Use our Contact / Feedback form or one of these email addresses:

Creative Commons License

Except where otherwise noted, dominoGuru.com by Chris Toohey is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.