Alert message from server side javascript

Hello,

I am developing one Xpage application. I need an alert message after submitting a request. In my Xpage I called an agent from “PostSaveDocument” event. And from the submit button I just wrote in server side JavaScript “save();”.

Can any one help me regarding this?

Thanks in advance.

Sandip

Subject: I fear you may not have explained this clearly…

  • Do you want to see an alert from SSJS?- Do you see a message you don’t expect?

  • Something else?..

Subject: Trigger alert

If you want to send a message to the user, as ever with XPages there are various ways you can do it, depending on what you want.

If you want to do an alert, you basially need to trigger client-side javascript after a server-side function. That’s what the onComplete event of a partial refresh is for (only available from 8.5.1). What you do in the onComplete is up to you. A basic option is to add an input field (id=“saveMsg”) with style=“display:none” so it’s accessible to CSJS but not visible to the user, then in your SSJS set the field to whatever you want to alert using getComponent(“saveMsg”).setValue(“YOUR MESSAGE”). Your save button can then call a partial refresh with CSJS “alert(dojo.byId(”#{id:saveMsg}“).value)” in the onComplete event of the button.

You can get fancier using a dijit dialog and showing the dialog - bear in mind you might need to bring the dialog back inside the Form tag (google “XPages dijit dialog” for various code to do this).

If you just want to write message on the screen, you can use a computed field bound to a viewScope variable, set the viewScope variable in the SSJS and call a partial refresh of that computed field or a panel containing it.

You may also be able to do something with facesContext.getResponseWriter(). I’ve not used that though.