0
votes

I have dialog box using dojo, that is placed on top of the xpages view action to present user value from one of the view first column and then do the excel to export process. I also added XSP.addClientLoad fuctionality as well to get values user selected.

on OK button of dialog box, I have below code on client side javascript.

var d=dijit.byId('#{javascript:compositeData.dialogID}');
 var SelectedValues = document.getElementById("#{id:SelectedValues}");
 SelectedValues.value =d.getSelectedValues();
 alert(d.getSelectedValues());
 context.redirectToPage("excelExporter2.xsp",false)

Which saves the value of the existing selection of dialog box to session scope variable in hidden editable field of Custom control.

Is this correct approach to set scope varaibles ?, also I want to loop through categorized view based session scope variable and export them on xpages so aftr this I want to trigger SSJS which will take care of excel to import part.

So my final aim is that based on user selection of dialog box, I want to run excel to export functionality (which is ssjs ) so please help me how to get started from here to jump into SSJS and also my approach of setting session scope variable is appropriate ?

1
context.redirectToPage() is server-side JavaScript. It can't run on a browser, so will throw errors. And scoped variables can't be directly updated by client-side JavaScript, because the variables are stored on the server. You need to trigger server-side code to update sessionScope, then redirect to your Excel export page from server-side. Go back to the basics of understanding what runs where, understanding partial refreshes, and particularly Extension Library dialog or you're going to have bigger problems with your XPages application.Paul Stephen Withers
Yes my question is that how to trigger server side javascript from client side javascript code which would do the sessionScope variable storing and export to excel. if you can share any reference would be great.poorv chauhan

1 Answers

0
votes

Do You have a part of code that has to be ran on client side? If not, try to write it on server side straight away. For example to do Export to Excel You could probably use "window.open('some_url')" rather than that.

Otherwise, You can use this trick to fire a SSJS event on XPage/Custom control:

Create an event somewhere on XPage. Make sure it has and ID property, and that the event name is something else than standard events (onChange, onClick). Put the server code in that event that You want to run.

<xp:eventHandler id="eventHandlerId" event="myEvent" submit="true"
    refreshMode="partial" refreshId="refreshId">
    <xp:this.action><![CDATA[#{javascript:peformSSJSAction();}]]></xp:this.action>
</xp:eventHandler>

Fire the event from client side Javascript.

XSP.allowSubmit();
XSP.firePartial(null, "eventHandlerId", "refreshId");

Parameter "refreshId" is the refresh ID of refreshed area during partial refresh after the code is done.