Session Expiration Warning - xpages

I have an XPages app that is supposed to save the main doc (and do a couple of other things) when the user clicks a button on the dialog box. The dialog box is presented by a CSJS function which runs according to a setInterval command. The dialog box and all the programming that present it are on a Custom Control. I have no problem displaying the dialog box, but have been unable to come up with a way to save the underlying document. I have other dialog boxes on their respective XPages, and saving the doc with a click (and some SSJS) works fine, but the same process doesn't seem to work if the dialog box is on a CC. I have searched all over the web, including StackOverflow, and haven't been able to find just what I need. Any ideas as to what I am missing?
Here's the code from one of my more recent attempts:
<xp:button value="Continue" id="button1">
<xp:eventHandler event="onclick" submit="false" id="eventHandler1">
<xp:this.script>
<![CDATA[
if (intvlID2) {
clearInterval(intvlID2);
}
var b18 = dojo.query('[id$="button18"]')[0];
if (b18) {
b18.click();
} else {
location.reload(true);
}
XSP.closeDialog('#{id:WarningDialog}');
]]>
</xp:this.script>
</xp:eventHandler>
</xp:button>
As you can see, it clears the interval first, then looks for a button on the underlying form. I've been able to verify that it does, in fact, find the button, but nothing happens with the click() command. The button it finds includes this save command that doesn't appear to execute:
document1.getDocument(true).save();
The button works perfectly when clicked by mouse or tapped by finger, but not when 'clicked' programmatically by another button on a CC.

The currentDocument global variable can be used to access the nearest dominoDocument datasource. Alternatively, the Extension Library dialog box has an additional parameter when closing the dialog box, the id of the refresh area. Maybe you can use that to trigger a save, something like setting a requestScope variable on close, and in the refresh area having code that does a save if the requestScope variable is set and, after save, clearing the requestScope variable?

Related

Xpages dojo dialog box selected values

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 ?
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.

XPages: ask a confirmation when saving and set a value if confirmed

I have a document that gets published using an xagent (that does all sorts of things to the document).
Before sending to the xagent, I would like to ask the user if he wants the effective date of the document to be set to today's date. For now, I don't have that field available in edit mode on the page, but I guess I'll need it.
The big question is how to ask a confirmation (do you want the date to be set to today?) and put the date in the field before actually saving the document and sending it to the xagent page. I already have some simple actions into that save button. Here is the code:
<xp:button value="Save and Publish" id="button6">
<xp:this.rendered><![CDATA[#{javascript:database.queryAccessRoles(session.getEffectiveUserName()).contains('[Admin]') && currentDocument.isEditable()}]]></xp:this.rendered>
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action>
<xp:actionGroup>
<xp:modifyField name="Status" var="pageDocument">
<xp:this.value><![CDATA[#{javascript:if(getComponent("publishLater1").getValue() == "1") {
return "Scheduled Publication";
} else {
return "To Be Published";
}}]]></xp:this.value>
</xp:modifyField>
<xp:saveDocument var="pageDocument">
</xp:saveDocument>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript: //remove the lock doc
//unlockDoc(pageDocument.getDocument().getUniversalID());
//for scheduled publications, a LotusScript agent will do the work
var res=facesContext.getExternalContext().getResponse();
if(getComponent("publishLater1").getValue() == "0") {
// Now load the publish Agent
res.sendRedirect(#Left(facesContext.getExternalContext().getRequestContextPath(),".nsf")+".nsf/xPublish?OpenAgent&docid=" + pageDocument.getDocument().getUniversalID());
} else {
//send to the drafts view, to show it has the clock icon in the draft view
res.sendRedirect(#Left(facesContext.getExternalContext().getRequestContextPath(),".nsf")+".nsf/adminDrafts.xsp");
} }]]></xp:this.script>
</xp:executeScript>
</xp:actionGroup>
</xp:this.action>
</xp:eventHandler>
<i class="fa fa-newspaper-o pull-left fa-2x">
</i>
</xp:button>
You could do it several ways I'd think. If you're using the extension library you could use a dialogBox. so your save and publish button opens a dialog box with your question or even additional fields. Then you add a cancel button of course to the dialog box but also a "continue" button. That button accesses the fields if you put any in or knows that they want "today's" date and then that button calls the xagent passing in any appropriate parameters.
Presumably pageDocument is a dominoDocument datasource. A dominoDocument datasource is either all read only or all editable. And SSJS has access to that datasource. So add another executeScript action and you can modify whichever other field you want to as well.
What I'd recommend, though, is to skip the simple actions and do everything in script. The SSJS editor allows you to see all the methods available for a dominoDocument datasource. With a little knowledge of LotusScript or a little investigation, it should be obvious which method to use to replace an item value for the "Modify Field" simple action (quick tip, again go to the datasource rather than the publishLater1 component) and which method to save the document. If you start breaking away from simple actions and building your confidence in SSJS, it will give you greater flexibility in the long run.

How to add an onComplete event to the Xpages extLib valuePicker control

I have an extensionLibrary valuePicker control on my XPage and I'd like to run some search code after user selection. How can I achive this. Any onComplete events? I'd like to omit an "onchange" event at the target field (user may change it manually and then I'd like to start search on Enter or Search Button click)
<xe:valuePicker id="valuePicker1"
for="TargetField" pickerText="Select"
dialogTitle="Select">
<xe:this.dataProvider>
<xe:simpleValuePicker labelSeparator="|">
<xe:this.valueList><![CDATA[#{javascript:getMyValues()}]]></xe:this.valueList>
</xe:simpleValuePicker>
</xe:this.dataProvider>
</xe:valuePicker>
From the source code, it looks like the Value Picker calls XSP.selectValue() passing in the dojoType of the dialog to show, by default extlib.dijit.PickerList. It's triggering an AJAX request to retrieve the values, but opening and closing the dialog is done via CSJS only. So there's no onComplete event like partial refresh. And there's no current hook to add CSJS to run when closing. But it would be possible to extend that JavaScript file and trigger that instead. I'm not sure in your use case what corresponding code you would then need for your Edit Box control.
My preferred method is to use the Dojo List Text Box to hold the selected values (rather than an Edit Box or other manually editable component), then use an onChange event on that target field. Personally I feel it gives a better user experience, discourages manual typing and avoids needing to validate the Edit Box for user input.

xpages how to force a partial refresh afterPageLoad

I asked this question a couple months ago, but there has been no response so I thought I would try again. I have a block of SSJS that manipulates a number of values. There are some computed fields that are impacted by these changes and they do not display correctly. I have a refresh button on the XPage and it does a partial refresh after which everything works fine. I need to somehow trigger a partial refresh on the a specific item (a panel in this case) as the last step in the afterPageLoad in the SSJS.
Any ideas?
Thanks
Refreshing Panels from SSJS without a button, link or something like that is a bit tricky.
But i think your problem is more located in the order in wich you are trying to compute your fields what about triggering your Code in a erlier event before those Fields are rendered, to avoid displaying the wrong values in the first place, maby post some example Code.
If you only want to refresh a the panel again after the page has bean loaded try this in the onClientLoad ClientEvent this could also fix it:
<xp:eventHandler event="onClientLoad" submit="false">
<xp:this.script><![CDATA[dojo.ready(function(){
XSP.partialRefreshGet('#{id:yourPanel}',{})
});]]></xp:this.script>
</xp:eventHandler>

Opened new document in xpinc. How to close window or redirect to parent document?

I'm XPage-ing a form in a big classic notes application, and I'm struggling to find a way to end the interaction with the form that presents a good UI. Here's my scenario:
1) Parent document (classic notes) is opened from a view
2) Button on parent document opens child document in XPiNC using notes:/// link.
3) Cancel button on child document XPage......
I've tried the following approaches:
a) Use window.close()
I've done lots of googling on this one, and various approaches don't seem to work for me. window.close() is supposed to work if you call it from a window that was opened with window.open, so I tried window.open("closeMe.xsp", "_self") to see if this would give me a window that could be closed by an xpage with window.close() in the onClientLoad client side event. No luck there. The following questions make suggestions but don't provide a solution (apart from a third party product)
How do I close my window in Xpage?
How to close xpages in notes client? I use CSJS window.close but it's not working
b) Redirect to parent document
My next idea was to redirect to the parent document - it's already open in the Notes client. However, I found that when I redirect (using facesContext.getExternalContext().redirect("Notes:///url" ) it does indeed jump to the parent document, but it leaves a blank window open in the tab where the XPage was.
My next try was to close the parent in the original calling LotusScript, then redirect to the parent in the cancel button. This works too - you get to the parent document, but then if you press the escape key or close the tab with the parent document, it leaves you with an empty window again.
Any ideas? I like the idea of being able to return to the newly-opened parent document because I could expect an embedded view to be refreshed with my new child document, but at the moment I'll take anything that works. :)
Cheers,
Brendan
You are stuck between a rock and a hard place. XPiNC and classic Notes don't mix that easily. But there is hope. Head over to the Composite Application Wiki. There you will find that you can open a composite instead of a document which allows you to have tabs and stuff inside a composite.
It is also the way a classic application and a XPages (publish/subscribe using the property broker) can exchange data. Make sure you read the comments too. Karsten has good further links.
I don't have a working example for what you exactly want to do, but Composite feels like the best bet you have.
I found a partial solution, Java is your friend. It works in a button should work in a link too. The only problem is when called from an event like onClose the current xpage looses focus and the current pages stays open. I tried to emulate send keys and it presses the ESC key. It works fine from a button in.
Button on CLick event
<xp:button value="Label" id="button1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:var robot:java.awt.Robot= new java.awt.Robot;var event:java.awt.event.KeyEvent=java.awt.event.KeyEvent;
robot.keyPress(event.VK_ESCAPE);
robot.keyRelease(event.VK_ESCAPE);
enter code here}]]>
</xp:eventHandler>
</xp:button>

Resources