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



Jun 5, 2012, 2:26 PM
10 Posts
topic has been resolvedResolved

Send data from CSJS to SSJS

  • Category: Server Side JavaScript
  • Platform: Windows
  • Release: 8.5.3
  • Role: Developer
  • Tags:
  • Replies: 4
 I have an Xpage that has a button the user can click to display an HTML table of data based on some search criteria they specify.
 
The data in the table is generated via CSJS ajax calls (to multiple dbs). 
 
There is another button on the Xpage that is meant to allow the user to export the data in the table to Excel. The button redirects the user to the Export Xpage which has the Export generation code in the afterRenderResponse event as per many examples on the net.
 
The problem is because the Excel generation code is SSJS on another Xpage, I need a way of passing the info generated by the CSJS to some sort of scope variable (e.g. sessionScope) so that I can access it from the Export Xpage.
 
Does anyone have any idea how I can do this? 
 
I have tried adding a hidden input control and setting it's value when I generate the table. Then in the Export button I attempt to access the hidden input's value to put it in the sessionScope, but it's value always seems to be null.  I try to access the field using getComponent("fname").getValue();
Jun 5, 2012, 3:56 PM
23 Posts
Re: Send data from CSJS to SSJS
 I am doing what you are describing.  I generate an HTML table that includes checkboxes for each row.  On selection (or for all of them if the top checkbox is selected) the UNIDs for the documents are written to a hidden field.
 
When the next action is performed, the value of the field is read and then used in a bean, in my case, but could also be thrown into a scoped variable. 

var x=getComponent("inputText1").getValue();

 
Another thought...just bind the hidden input to a scoped variable. 
Jun 5, 2012, 11:38 PM
10 Posts
Re: Send data from CSJS to SSJS
 I must be doing something wrong because I have tried something similar to what you have described, but no luck.
 
So I have a hidden input with the following code on my Xpage: 
 
<xp:inputHidden id="inputHidden1"
value="#{javascript:sessionScope.analysisData}"
binding="#{javascript:sessionScope.analysisData}">
</xp:inputHidden>
 
Then I have a generate analysis button that calls functions in a CSJS script libary to generate an analysis table. 
 the last two lines run by this code are:
 
document.getElementById("view:_id1:inputHidden1").innerHTML = exportData; //exportData is a string
alert(document.getElementById("view:_id1:inputHidden1").innerHTML);
 
Note, I have tried .value as well as .innerHTML. The alert works and displays the data correctly. I can't embed SSJS to get the field id here as that doesn't seem to work in CSJS script libraries.
 
Then i have my export button: 
 
<xp:button value="Export to Excel" id="button2">
<xp:eventHandler event="onclick" submit="true" refreshMode="complete" immediate="false" save="false">
<xp:this.action>
<xp:actionGroup>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript:
print("inputhidden:");
print(getComponent("inputHidden1").getValue()); //This prints null
print("analysisData");
print(sessionScope.analysisData); //This prints null

//sessionScope.analysisData = getComponent("inputHidden1").getValue();}]]></xp:this.script>
</xp:executeScript>
<xp:actionGroup>
<xp:this.condition><![CDATA[#{javascript:
sessionScope.containsKey("analysisData");}]]></xp:this.condition>
<xp:openPage name="Export.xsp"></xp:openPage>
</xp:actionGroup>
</xp:actionGroup>
</xp:this.action></xp:eventHandler></xp:button>
 
 Can you see what I might have done wrong?
Jun 6, 2012, 12:30 AM
10 Posts
Re: Send data from CSJS to SSJS
 It would appear the issue was with my data binding for the hidden input field.
 
On the data tab for the field properties, i had simply select "Javascript" and typed "sessionScope.analysisData" into the script box. 
 
This does not work. To bind the field correctly I needed to select "Advanced",  change the drop down to "Use Scoped Variable" and then select sessionScope and provide the variable name. 
 
Thanks for trying to help Russell. 
Jun 6, 2012, 8:15 AM
126 Posts
Re: Send data from CSJS to SSJS
Just to note your hardcoding the full id of the hidden input in the CSJS, this is not necessary you can use the below to generate it:
 
document.getElementById("#{id:inputHidden1}");

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