« Welcome to Dojomino | Main| xhrPost to Domino »

Modifying Dojo to use Domino's OutputFormat=JSON

Category      
Bookmark : del.icio.us  Technorati  Digg This  Add To Furl  Add To YahooMyWeb  Add To Reddit  Add To NewsVine 

With Domino 7.0.2 you can get a JSON formatted response from Domino server's View URL commands, things like ?ReadDesign and ?ReadViewEntries. By adding the argument &OutputFormat=JSON the Domino server will produce JSON instead of XML. The Content-Type of this output is application/x-javascript. When integrating with Dojo 0.4.2, this is an issue as the standard AJAX type call from Dojo, dojo.io.bind(), recognizes many different Content-Types, but application/x-javascript isn't one of them.

To resolve, I chased down the 2 lines of code in the default dojo.js file and modified them to add that mimetype. It is available here. The 2 lines are line 2695 and 2791. More...

Why mod dojo.js?

You don't have to by any means. But I wanted to work with Domino's JSON output and figure out how to get Dojo to accept it. Here's some example code that will get view entries back as json:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html>
<head>
<script type="text/javascript" src="dojo.js"> </script>
<script type="text/javascript">
function initView() {
    var kw = {
        url : '/view2007/baseball.nsf/Players?ReadViewEntries&OutputFormat=JSON',
         mimetype: 'application/x-javascript',
        method: 'GET',
         load: function(type, data, evt) {
            var myData = data;
            var o = dojo.byId("output");
            o.innerHTML = data.@toplevelentries + " entries in the Players view";
        }
    };
    dojo.io.bind(kw);
}
dojo.addOnLoad(initView);
</script>
</head>
<body>
<div id="output"></div>
<div id="dojoDebugOutput"></div>
</body>
</html>

Comments

Gravatar Image1 - I've not looked in detail at the 0.9 source code, but my first search reveals that the structure is quite different.

I'll dig in a little deeper and find out, but it may be a few days as I'm up to my eyeballs in a project this week.

Gravatar Image2 - In .9 I am using this method to return JSON to the dojo.xhr function and it works great.

dojo.xhrGet( {
url: /viewName?readViewEntries&outputformat=JSON,
handleAs: "json",
handle: function(response, ioArgs) {
...
}
});

But what if you want to search a view? Have you found an easy way (or at least a logical way) to get JSON format back when searching a view? The method I am using is extremely convoluted and will be a nightmare to maintain.

Oh, what I wouldn't give for ?searchViewEntries&outputformat=JSON! Emoticon

Gravatar Image3 - Is the Dojo hack still needed with the 0.9 Dojo code stream? It seems 0.9 is stable enough to start developing with it.
"-) stw

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)