icefaces modal popup timeout issue - icefaces

Have a question regarding something which has been bugging me for some time now.I'm using icefaces to generate a modal popup with search fields.Clicking search kicks off a screen scraper for a particular website.
My problem is this.If you enter some pretty generic terms,obviously the scraper will take longer to complete which causes a timeout.The timeout causes the modal popup to freeze and it can't be closed.
How can I gracefully close the popup and navigate to another page if a timeout occurs?

You can create a thread, start it & make it to sleep the amount of time that is session max timeout interval.
You can then redirect to another resource after thread resumes as follows:
#Thread's run method
//...
try {
Thread.currentThread().sleep(TIMEOUT_INTERVAL);
} catch (InterruptedException e) {
e.printStackTrace();
}
URL url = new URL("REDIRECT_PAGE");
url.openConnection();
//...
But if your search process completes prior to timeout interval, you can kill the thread.

Related

Recognize browser close in wicket

Is there a reliable way to detect the closing of the browser tab or window on the server side in a wicket application?
It must work under firefox version 68.11.0 or higher. I use wicket 8.8.0.
I tried it with websockets and catching the connection close event. But unfortunately this event is also raised when a page is refreshed (F5).
new WebSocketBehavior() {
#Override
protected void onClose(ClosedMessage message) { // invoked on tab close, window close and unfortunately on page reload
super.onClose(message);
log.info("Connection for page = '{}' closed.", message.getKey());
}
}
From browser point of view there is no difference between closing the tab and refreshing the tab. In both cases the browser fires beforeunload JavaScript event and closes all open connections (WebSocket, ServerSideEvent, Ajax).
So, you can use
page.add(new AjaxEventBehavior("beforeunload") {
#Override public void onEvent(AjaxRequestTarget target) {...}
});
but this just tell you that the user navigates away from the current page. There is no info what comes next.

how to know when an action was performed and close automatically the modal

Let's consider the situation where we send, for example, a request and we are waiting a response.
While we are waiting a modal pops-up with a glyphicon, showing that the request is being processed. The result of this process is going to be an object, when it is null it means that the request was accepted with success, otherwise this object will come with an error message.
I would like to close the modal after receiving the notification, no matter if it was successful or not
can anyone give me an hint of java and wicket?
Wicket gives you full control over ajax request life-cycle and you can implement your own listener as shown in the user guide
If you want to close the modal window after notification recieved, you can make this modal window invinsible, just:
public void recieveNotification(AjaxRequestTarget target) {
Notification notification = service.getNotification;
target.add(modalWindow.setVisible(false));
}
and you wouldn't see it.

Click Event handler

when i click on a button the click event handler executes a code . If by mistake(if browser hangs) i click on the button twice the code gets executed twice.i dont want that to happen.
Any suggestions to stop that?
i suppose i should use a schedular or timer but i am not sure
below is the code:
public void onSendButtonClicked() {
disableButtons();
eventBus.fireEvent(new SendEmcsDeclarationEvent(getDeclaration(), getMsgType()));
}
You can - as Abdullah mentioned - disable/enable every widget in GWT with
widget.setEnable(false)
and
widget.setEnable(true).
If you want to lock the whole screen, create a modal popup, show it, after the button is pressed and hide it, after the code has finished.
public void onSendButtonClicked() {
myProgessBar.show();
eventBus.fireEvent(new SendEmcsDeclarationEvent(getDeclaration(), getMsgType()));
myProgressBar.hide();
}
If you are using a async call, you have to hide the progessbar in the callbacks. In this case the finally command might be executed before the callback is executed. In your case it might be a good idea to create a ShowProgressBarEvent and HideProgressbarEvent, so that you can use the progressbar in your whole application.
If your are using a widget library f.e.: GXT, you will find a ProgressBar ready to use.
Hope that helps.
The best way I can think of is to enable/disable the button itself so as to make sure that the code in handler is not called again until before the previous call finishes up.
public void onSendButtonClicked()
{
try
{
disableButtons();
eventBus.fireEvent(new SendEmcsDeclarationEvent(getDeclaration(), getMsgType()));
}
catch (Exception ex)
{
throw ex;
}
finally
{
enableButtons();
}
}
When I create a button, I always also add an animating gif (ajaxloader).
When the button is clicked I make the button invisble, the ajaxloader visible.
When the action is done, I make the ajaxloader invisible, and the button visible.
This way the user has some visual feedback that something is happening (what you don't get when disabling the button), and not the entire application gets blocked (as a modal does) which is one of the plus points using ajax.

NSApplication.SharedApplication.Terminate doesn't actually terminate my application after unhandled exception

I am developing a simple application for OSX with MonoMac. When my application experiences unhandled exceptions, I catch them with:
AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
Unhandled(e.ExceptionObject as Exception);
Inside the function Unhandled(), I log the exception and run a modal window to inform the user that something went wrong.
I then proceed to test this by throwing a regular Exception somewhere in the application. The crash report window appears as it should, and the error is logged.
But after this window has been closed, I would expect the application to quit, as it would have done if I hadn't caught the error. It does not; the application's main window and the dock icon are still there, but the window is completely frozen.
If I remove the above code line, the application closes completely when it crashes.
I try to force the application to quit by calling:
NSApplication.SharedApplication.Terminate(myAppDelegate);
But this seems to do nothing at all. I use the exact same code line in the application's Quit button, and there it works as expected, so there must be something special about the application state after catching an unhandled exception. But what?
I have overriden the following in my AppDelegate just in case, but it doesn't seem to make any difference:
public override NSApplicationTerminateReply ApplicationShouldTerminate (NSApplication sender)
{
return NSApplicationTerminateReply.Now;
}
I thought that maybe displaying a modal form did something to the application state, but after testing I see that whether I show the modal form or not makes no difference. Still the frozen main window instead of closing.
EDIT: I must've done something wrong when testing this. It actually works as it should if I don't display the error form.
Any ideas?
I don't have an answer for you exactly, and a comment wouldn't hold my code sample; but I can tell you that I'm conceptually doing almost exactly the same thing in my application and it works just fine. My code:
private static void OnException(Exception ex)
{
new NSObject().InvokeOnMainThread(() => {
try
{
using (ErrorWindowController frmErrorMessage = new ErrorWindowController(ex))
{
Console.WriteLine(ex);
NSApplication.SharedApplication.RunModalForWindow(frmErrorMessage.Window);
}
}
finally
{
NSApplication.SharedApplication.Terminate(NSApplication.SharedApplication);
}
});
}
EDIT:
Make sure you are stopping the modal session when you close the window, or the call to RunModalForWindow will never return.
I close my modal window using a button, something like this:
partial void butClose_Click(NSObject sender)
{
this.Window.OrderOut(sender);
this.Window.Close();
NSApplication.SharedApplication.StopModal();
}

How do I close the splash screen in an eclipse RCP application?

In an eclipse RCP application, a splash.bmp is used as the splash screen. It closes after about 5-6 minutes of the application being run. I want it to close as soon as some UI displays. I tried using Platform.endSplash() and also applicationRunning() of the application context just before PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor()).
It fails to close the splash screen.
Any suggestions would be helpful. It would also be okay if I could close the splash screen after about 10 -15 seconds.
public Object start(IApplicationContext arg0) throws Exception {
Display display = PlatformUI.createDisplay();
int returnCode = 0;
try {
//arg0.applicationRunning();
Platform.endSplash();
returnCode = PlatformUI.createAndRunWorkbench(display,
new ApplicationWorkbenchAdvisor());
if (returnCode == PlatformUI.RETURN_RESTART) {
return PlatformUI.RETURN_RESTART;
}
return PlatformUI.RETURN_OK;
} finally {
//some other code here.
display.dispose();
}
}
I would expect the splash screen to close when everything is initialized, not after a set amount of seconds. Otherwise you don't even need one.
According to this thread, you should make sure to call the Platform.endSplash() method in the right context, meaning the method start(IApplicationContext context)
If you already do this, please provide some code to help us understand your problem
The closing of a splash screen is handled by the created StartupMonitor in Workbench.
After the workbench part is created (as you say, "as soon as some UI displays"), it will be cycling through all registered startup services. The fact that you have your workbench visible and have to wait ~5-6 minutes (or seconds) for your splash screen to close means you have another startup monitor preventing your desired UI transition.