質問

I have this situation:

I have an IndicatingAjaxButton. In the onSubmit method some operations get done and then the setResponsePage(otherPage); is called

While the operations are still in progress the busy indicator is visible. But then when the operations are done the indicator is gone while the user is still on the same page, capable of doing other activities, while the browser is busy opening the other page.

My question is how to make the indicator still visible as long as the browser is busy opening the otherPage.

Thank you

役に立ちましたか?

解決

First of all, you'd need to make sure you really need to do this in an ajax request. I wouldn't see it necessary unless you're doing setResponsePage() only depending on certain conditions, and else performing some Ajaxy operation.

If you don't need Ajax, I'd recommend dropping it and just sending a regular request. You can code a busy indicator client or Wicket side and make it show with javascript (maybe in body.onunload for a general way?).

But, if you really want to achieve this, you should understand why the indicator is being hidden. Wicket prepares the javascript that will be executed upon call completion (success or failure). The relevant method is AbstractDefaultAjaxBehavior#generateCallbackScript():

final CharSequence onSuccessScript = getSuccessScript();
final CharSequence onFailureScript = getFailureScript();
...
if (!Strings.isEmpty(indicatorId))
    {
    String hide = ";wicketHide('" + indicatorId + "');";
    success = success + hide;
    failure = failure + hide;
}

Here Wicket is preparing the javascript wicketHide(id) call that will effectively hide the indicator once the request is completed (and upon sucess or failure).

I've never tried to do this, but probably overriding getFailureScript() and getSuccessScript(), to make the script return before executing wicketHide(id), in your Ajax behavior should do the trick:

protected CharSequence getSuccessScript() {
    String script = super.getSucessScript();
    return (script != null ? script : "") + ";return false;";
}
protected CharSequence getFailureScript() {
    String script = super.getFailureScript();
    return (script != null ? script : "") + ";return false;";
}

Notice this would always leave the indicator shown, and never hide it. If you wanted to conditionally hide it or not depending on if a setResponsePage is done or not, you could, for instance, define a js variable by means of AjaxRequestTarget, and return conditionally in your getSucessScript() and getFailureScript() implementations.

Wicket's sources are (at least for me) amazingly clear to read and understand. They can help you lots at understanding how it really works and how can you tweak it to suit your needs.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top