Show ’n’ tell II: Domino content types trick

Show-n-tell Thursday logoHere’s a little nugget that may be of interest. I’m currently working on the next release of DominoWiki, and one of the bugs I really wanted to fix is related to the way in which “resource documents” (CSS files, XML files, Javascript, etc.) are rendered—namely, with incorrect MIME types. It would be fantastic if we could change the content types of individual documents when rendered by Domino, but we can’t: content type (and character set) are attributes which get set at the form level.

In assessing how to address this for DominoWiki, I looked at a few work-arounds (for security reasons you can’t change some headers with @SetHttpHeader), including buggering about with dollar-fields, screwing with form design programmatically, DXL, etc.

All to no avail. I wanted something simple, and something pretty robust. Everything I tried was quite brittle, or had an unacceptable overhead. For example, I was contemplating rendering the content of the resource documents via an agent, but given DominoWiki’s heavy use of a Webqueryopen agent to convert wiki mark-up into HTML already, I didn’t really fancy that (although one of the project chefs, Paul, put together some elegant code to do just this).

So, the solution I settled-upon is the subject of this show-and-tell post. Here goes:

In the Notes client, I have a “Resource” form. This has a drop-down list which allows for the selection of an appropriate MIME type for that document. The list contains all the stuff you’d expect: text/html, text/plain, application/ecmascript, and so on and so forth. A rich text field in the document stores the actual content—code, XML, whatever.

In rendering to the web, I use a different form, or more accurately, forms. Yep, I use an old favourite: view form formulas! The code is very straightforward, and looks like this:

	MimeType="text/css"; "rsrcCSS";
	MimeType="text/javascript"; "rsrcJS";
	MimeType="text/xml"; "rsrcXML";
	MimeType="application/ecmascript"; "rsrcECMA";
	MimeType="application/javascript"; "rsrcAppJS";
	MimeType="application/xhtml+xml"; "rsrcAppXML";
	MimeType="application/xml"; "rsrcAppXML";
	MimeType="text/plain"; "rsrcPlain";

For each MIME type, I took a copy of the web version of my Resource form, and changed its content type value. So, in the code above, if the content type has been set to text/javascript, the resource data is rendered to the web using a form called “rsrcJS”, which in turn has a defined content type that matches the required MIME setting in the resource document. Simple! I could have been flashier with the code, and just named the forms the same as their MIME type, thus removing the need for as long an @If statement as above, but hey, let’s make this friendly.

This seems like a bit of a kludge, but it works really well, produces compliant output, and shouldn’t need to be altered much—as you can see in the formula, I cover all the main content types you’d want to use in such a solution. Rather than it being an out-and-out hack, for me it approaches “righteous hack” and I can sleep at night. :-)


  1. Hello Ben,
    Thanks for your work on DominoWiki and the article above. I've started using DominoWiki a few weeks ago and came across the following bug: when you start a line with a space to get the courier font, it works. Enter a new line and start that line with a space also and it will fall back to the proportional font. Could you please have a look?

    GeraldGerald Mengisen#
  2. File a bug sir! This is an unrelated weblog post ;-) Ben Poole#
  3. About copying the whole forms - are you putting the real contents onto a subform? Or are those forms just too simple to do that?

    CheersJosef Prusa#
  4. Good question. Ordinarily, I would indeed use subforms, as each form is identical bar the content type. However, in this particular example I didn’t bother: the web version of the resource form contains 3 or 4 fields, no formatting, nothing. So, each form is just a straight copy (you can see this in the current version of DominoWiki on the OpenNTF site).Ben Poole#
  5. Why not let the user create a document with the appropriate form (css, xml, javascript, etc.) rather than picking from a drop down? From reading this article solely, it does not appear that any advantage is gained by using a single resource form. It is not as if you have been able to eliminate the need to design individual forms.

    Wouldn't it be great if the mime/type (and most other properites) could be set by a formula.

    Richard Collette#
  6. Why? Simple. For this app I don’t have nice Notes client versions of the various resource forms ready for users to create and edit documents with. Like I said, the web-oriented version of the form has no formatting, no buttons / actions, nothing.

    Obviously if you’re just doing this stuff on the web, then the issue goes away and you just use the relevant form. I should have made it clearer that this solution works for DominoWiki but obviously YMMV!

    Re setting document properties via formula: amen to that!Ben Poole#
  7. >>File a bug sir!<<
    OK, done.Gerald Mengisen#
  8. Nice one, Ben! Very sneaky. My favorite kind of hack, using a forgotten feature (form formulas) to get around a lack in another feature. Bravo!Rob McDonagh#
  9. Glad you finally caught up Ben. You could have just asked to colleague ya know. You dont have to look clever all the time.John Z Marshall#
  10. [smiley poke_tongue] Mate, it’s the undeniable thrill of actually writing code again. I can’t help it.Ben Poole#
  11. Of course there a simpler way. Save all you content type forms with alias that is the content type e.g. (webPage) | text/html . Then in your content form have a field called say MimeType and store text/html in it. Then your view formula becomes the value of the MimeType field so no IF statement.

    Hide these content type forms from Notes and dont forget to include all the CGI fields you might need in each one.

    John Z Marshall#

Comments on this post are now closed.


I’m a software architect / developer / general IT wrangler specialising in web, mobile web and middleware using things like node.js, Java, C#, PHP, HTML5 and more.

Best described as a simpleton, but kindly. You can read more here.