I have an iNotes List view object which lists the documents I want, and the related REST components. In the “OnSelectEntry” method I have the following code.
var unid = items[0]["@unid"];
var myUrl = "test.nsf/main.xsp/docPathInfo/unid/" + unid;
var h;
if (window.XMLHttpRequest){
h = new XMLHttpRequest();
} else {
h = new ActiveXObject("Microsoft.XMLHTTP");
}
h.onreadystatechange=function() {
if (h.readyState == 4 && h.status == 200) {
var myObject = eval('(' + h.responseText + ')');
var result = dojo.byId("#{id:inputText1}");
result.value = myObject.field1 + " " + myObject.field2;
}
}
h.open("GET",myUrl,false);
h.send();
This code works perfectly if the NSF is hosted on a server, but if I have it local it fails with the following:
uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nslXMLHttpRequest.send]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://127.0.0.1:50113/xsp/.ibmxspres/.mini/dojo/.en/@Wc&@Eab&@Eya&@lu.js :: anonymous ::
I need this to work on the client. Is this the correct way to make the call back on the client?
I have tried changing the ACL access as well but it doesn’t appear to help. I’ve also tried a absolute URL instead of a relative one.
[Update]
I tried changing to a Dojo call instead as follows.
var x;
var myCallback = function(data, ioArgs)
{
var myObject = eval('(' + data + ')');
var result = dojo.byId("#{id:inputText1}");
result.value = myObject.field1 + " " + myObject.field2;
}
dojo.xhr("Get", {
url: myUrl,
handleAs: "text",
timeout: 10000,
load: myCallback
});
When I run this code, it works fine on the server but when I run it on the client it doesn’t work. I get the following message in the XPages.log file.
1/10/13 10:45 AM: Internal warning: Check access being called outside of a request
1/10/13 10:45 AM: Internal warning: Check access being called without a valid session/database
OK I am not sure about how you would do it using REST on the client, but you can make a XSP.partialRefreshGet() call and that should work.
So for your code you would do the following:
Then in your “someDummyField” set that to computed for display and have the code like this:
For recommended reading on this there is the “XPages Portable Command Guide“, Page 176.
Just to expand a little bit on this, you should use the XSP.partialRefreshGet() instead of XHR, as AJAX calls can corrupt the backend document if not done correctly. This is also documented in the same book.