This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Aug 8, 2011, 7:02 PM
27 Posts

Manually passing data to SSJS via AJAX?

  • Category: Server Side JavaScript
  • Platform: All
  • Release: 8.5.2
  • Role: Developer
  • Tags: partialRefresh SSJS client site javascript
  • Replies: 2
 ...this is a little off the beaten path, but I'd like to be able to pass a parameter and process it on the server side using SSJS.
 
Specifically, I have some client side javascript code that is currently calling a custom event handler:
 
<xp:inputRichText id="inputRichText1"> 
<xp:eventHandler id="saveMyDoc" event="onfubar" submit="true" refreshMode="partial" refreshId="inputRichText1" execMode="partial">
<xp:this.action><![CDATA[#{javascript:
mydoc.save();
}]]></xp:this.action>
</xp:eventHandler>
<xp:this.value><![CDATA[#{javascript: mydoc.getItemValue("description")}]]></xp:this.value> 
</xp:inputRichText> 
 
...and I am using custom client side javascript to call the "saveMyDoc" eventHandler, like so: 
 
 executeOnServer('saveMyDoc');
 
...which wraps around client side XSP._partialRefresh - and this successfully calls "mydoc.save()" on the server, but what I need to do is pass some text data to save as well.
 
I see that the XSP._partialRefresh, which looks like (found in xspClientDojo.js.uncompressed.js):
 
this._partialRefresh = function x_prfh(method, form, refreshId, options) 
 
...permits a options.params value to be passed with it, but does anyone know how to access this on the server side with SSJS? 
 
Many many thanks in advance!   (I've searched and searched and am stumped!)
Cheers, 
 
Alex 
 
PS - The "executeOnServer" was copied from Jeremy Hodge's excellent blog post
 
var executeOnServer = function () {
    // must supply event handler id or we're outta here....
    if (!arguments[0])
        return false;
    // the ID of the event handler we want to execute
    var functionName = arguments[0];

    // OPTIONAL - The Client Side ID that you want to partial refresh after executing the event handler
    var refreshId = (arguments[1]) ? arguments[1] : "@none";
    var form = (arguments[1]) ? XSP.findForm(arguments[1]) : dojo.query('form')[0];

    // OPTIONAL - Options object contianing onStart, onComplete and onError functions for the call to the 
    // handler and subsequent partial refresh
    var options = (arguments[2]) ? arguments[2] : {};

    // Set the ID in $$xspsubmitid of the event handler to execute
    dojo.query('[name="$$xspsubmitid"]')[0].value = form.id + ':' + functionName;
    XSP._partialRefresh("post", form, refreshId, options);
Aug 8, 2011, 8:17 PM
272 Posts
Re: Manually passing data to SSJS via AJAX?
You can retrieve the data specified on the params property in SSJS using the param object.
 
For example:
var pOpt =  { "param1": 1, "param2" : 2 }
 
If pOpt is added to params - parameter of the partial refresh, it can be accessed in SSJS like this:
 
print (param.param1);
print (param.param2);
 
Hope this helps
 
Sven
 
 
 
 
Aug 10, 2011, 9:37 PM
27 Posts
Re: Manually passing data to SSJS via AJAX?
Many thanks - this is exactly what I was looking for!
 
In a completely unrelated note, if one needs access to the console.log file to see the output of the print statements and they don't have direct access to the console or the server, this code stuck in an XPage will give you access to the previous 50 lines: 
 
<xp:text escape="false">
<xp:this.value><![CDATA[#{javascript:
var html = '';
var logfile:java.io.File = new java.io.File("<your path to domino data>/IBM_TECHNICAL_SUPPORT/console.log");
var fr:java.io.FileReader = new java.io.FileReader(logfile);
var br:java.io.BufferedReader = new java.io.BufferedReader(fr);
var a = new Array();
var s = br.readLine();
while(s != null) { 
a.push(s);
s = br.readLine();
}
for(var i=(a.length-1);i>a.length-50;i--) {
html += a[i];
html += '<br/>';
html;
}]]></xp:this.value>
</xp:text>
 

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal