Where should I use XSP.endAjaxLoading()? - xpages

I have a Xpage that takes too long to load. So the client ask me to do a loading indicator.
I searched and found XSP.startAjaxLoading(), that I put in onClientLoad event of the Custom Control.
But now I don't know where should I put XSP.endAjaxLoading() to make the loading screen go away.
I'tried to use in afterRenderResponse and beforeRenderResponse: view.postScript("XSP.endAjaxLoading()"), since this comand is CSJS, but it doesn't work.
Thanks in advance.

I think you want to put it in the onComplete event. That can be difficult to find. You typically need to use the outline control to find it.
I have a video demo on NotesIn9 that has an example on this.
http://www.notesin9.com/2016/02/19/notesin9-188-adding-a-please-wait-to-xpages/?unique=http%3A//www.notesin9.com/2016/02/19/notesin9-188-adding-a-please-wait-to-xpages/

Your attempt (view.postscript) works only with full/partial updates and does not work for page loading.
You have used onClientLoad - which is executed when your page is finished with loading. I guess you get ajax animation after a while and it won't stop.
You should make preload screen - very simple XPage which starts animation and does not care to turn it off. In onClientLoad event redirect to your slow XPage. That will discard the animation.

I'd highly recommend using the Standby Dialog XSnippet https://openntf.org/XSnippets.nsf/snippet.xsp?id=standby-dialog-custom-control. I use it as a standard in all XPages applications.

I used this answer as solution: https://stackoverflow.com/a/35481981/5339322
I've saw it a few days ago, what made me think twice is that using this i should know what is doing my XPages to delay. I ran some tests and discovered what, and it was a call to a method in the afterRestoreView event, then I migrated it to onClientLoad event and used the solution in the answer above cited.
But I'm afraid that I have to keep an eye on it, so if someone adds some code that delays in one of the another events of XPages I have to move it again, of course, if it's possible, if it's not, I'll figure it out something diferent.
Thanks for all the answers ans comments.

Related

Wait message with full refresh in xpages

I am developing an application on xpages and would like to put a wait message while there is an ongoing processing. There are several articles that indicate how to do, but this only functional with partial update. I need the message, preferably with lock and an animated gif to work with the full update.
Problem is that a full refresh will reload the page, to get this working you need to load the page inside an iframe and place the standby code in the top page.
If you do something you need to call parent.window.dothestandby()
and in onload on the page inside the iframe call parent.window.hidestandy()
Take a look at this NotesIn9 video by David Leedy and watch from 5 minutes and see if it helps:
http://www.notesin9.com/2016/02/19/notesin9-188-adding-a-please-wait-to-xpages/
What I did was use the technique described in the link below, from an article by Brad Balassaits. In the various techniques mentioned, I implemented the one that inserts the waiting animated gif into the triggered button. From the techniques suggested and researched this was the one that would least impact when there are changes of adjustments in the application.
Brad Balassaiti article

XPages: Show busy dialog when tabPanel clicked on?

I'm using an XPages Tabbed Panel for the first time. It's generally working well, but I have a lengthy process that runs the first time one tab is clicked on, so I would like to display a client-side busy dialog that we routinely use when it's switched to. I've tried to attach some client-side JS to the associated tabPanel's event handler (with submit="true"), but that doesn't seem to work. It executes the client-side JS, but doesn't switch tabs anymore. (I am returning true in the client-side event handler.) Is there another approach that might work? FYI, I was assuming that I could call view.postScript(...) at the end of my lengthy code in order to remove the busy dialog.
As usual with my questions, I can't post code to demonstrate this, sorry.
Thanks,
Reid
I use this post: http://xpagesera.blogspot.com/2012/05/add-ajax-loading-control-in-xpages-for.html
to great effect for this. Here is the text of the post:
Add AJAX “Loading..” control in XPages for Partial Updates
This is a two step process:
Add following Dojo modules to your XPage. 
<xp:this.resources>
<xp:dojoModule name="extlib.dijit.ExtLib"></xp:dojoModule>
<xp:dojoModule name="extlib.dijit.Loading"></xp:dojoModule>
</xp:this.resources>
 
Add following lines to the EventHandler of your button/link which is going to be used for Partial Update: 
<xp:this.onStart><![CDATA[XSP.startAjaxLoading()]]></xp:this.onStart>
That’s all ! 
A similar “Please wait..” dialog will appear and will display the page again once the Partial Update is complete..

Partial refresh in XPages causing other controls to not execute event handlers?

I have an xpage with a bunch of controls on it. One of them is a simple label that I'm updating with a partial refresh every five seconds. (I'm implementing a document locking scheme, and the label indicates whether someone has locked the document.) A button on the page fails to execute its event handler if I press it while the partial refresh of the label is occurring. At other times, it works fine. Is this a known issue, or is there perhaps something else going on that may explain this behavior?
(I'm unable to post sample code, unfortunately.)
You need to change your approach. Instead of a partial refresh, have an independent Ajax call to an XAgent for your locking (IMHO 5 sec is way to frequent, the WebDAV standard uses 30sec).
The openNTF WebDAV project has locking code you might be able to repurpose for your needs.
The independent Ajax call frees up the jsf lifecycle to run your other events.

showing Wait Screen using LWUIT in J2ME?

Is there any way of showing Wait Screen, while some processing is done in backend, using LWUIT in J2ME ? if yes then how if no then is there any alternate ?
You can look at progress bar with LWUIT. Sample Wait screen used in the makeover demo and the browser demo application in current LWUIT Repository. Also see here.
I had this issue as well, but got a workaround: these suggestions here seemed not to be the best for me. The dialog when it displays will block any other action except it is discarded, even if it was created with no commands.
What I did was to add a wait screen to the BorderLayout.CENTER of the main container or the Form, then when the thread running my background task finishes, the component is now replaced with the loaded component.
I dont know if anyone would find this useful since this has already been answered. I just felt like posting my own trick.
You can start a thread in which you do your stuff of getting data and all and in the UI thread show the loading dialog and then dispose that loading dialog once you are done with your services call.

How to control over browser back button

I want a confirmation window on click of a browser back button. If I press yes then the previous page will get load ortherwise I will remain in the same page?
Any suggestion is highly appreciated.. But please be on track.. my question is straight forward
thx in advance..
Why do you want to do that?
You can prevent them from leaving the page by using Javascript, but if you can't use that, it's not possible to do anything about it.
Generally you should use the unload event in the body (in jQuery for instance, just add
jQuery(window).unload(function(evt){
if(!confirm('Do you really want to leave')){
evt.preventDefault();
}});
Prototype have something similar, and for pure Javascript, I guess that it still depends on the browser you're using, but window.unload = function(evt){return false;} might work.
Don't remember the correct syntax for it though.
but I do not know if you can limit that for only the back or if it will trigger for all the unloads (like clicking on a link, closing the browser etc.)
If you want to stop them because they might have unsaved data in a form, then that is ok. If you want to stop them from going back for another reason than that, I think you should rethink why.
Generally if using the back button can cause issues you already have bigger problems.
What you probably want to do is check that you do things like this:
Use POST for all requests that alter data
Use nonce's (unique ID's) to enure forms don't get submitted twice
I use noscript for this very reason. I insist on having control of my browser not the site that I am visiting. I only allow scripts for certain sites. For any site that disables my back button,I don't allow it to run scripts.

Resources