You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Boris Goldowsky <bg...@cast.org> on 2017/05/03 15:52:18 UTC

AjaxCallListener and promises

Is there any way to use a method that returns a promise as the onBefore of an IAxaxCallListener?  I don’t want the ajax operation to move forward until the promise resolves.  Due to the nature of promises in Javascript, there doesn’t seem to be a way to simply wait for it.

Boris


Re: AjaxCallListener and promises

Posted by Martin Grigorov <mg...@apache.org>.
Thanks for sharing this solution, Boris!

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Fri, May 12, 2017 at 3:23 PM, Boris Goldowsky <bg...@cast.org>
wrote:

> For anyone who may have a similar issue and find this thread, here’s the
> workaround I used.
>
> Desired behavior was to have an AJAX submit on a form that includes a
> drawing widget.  The drawing can’t be saved directly; it needs to be asked
> to export its data into a hidden text field which can be saved.  The
> widget’s export operation returns a Promise.
>
> Strategy:
>
> 1) Instead of an AjaxSubmit button, I’m using a regular <button>
> 2) That button has an onclick that invokes the export operation, with a
> “then” clause that emits a custom javascript event.
> 3) I attach an AjaxFormSubmitBehavior listening to this custom event, so
> the form is submitted when the data is ready.
>
> I think it would be a nice feature in the future to think through a
> reasonable integration of the ajax handlers with Promises, as they are
> likely to become more commonly used now that they are reasonably
> standardized.
>
> Boris
>
>
> On 5/3/17, 3:08 PM, "Martin Grigorov" <mg...@apache.org> wrote:
>
>     Hi,
>
>     No, Wicket doesn't use the return values for all handlers but
>     "preconditions" [1].
>     And even for preconditions the only value that matters is the literal
>     *false.*
>
>
>     1.
>     https://github.com/apache/wicket/blob/b24decd2f60983c11e75e5f2c34d0c
> 6a93b56426/wicket-core/src/main/java/org/apache/wicket/
> ajax/res/js/wicket-ajax-jquery.js#L614
>
>     Martin Grigorov
>     Wicket Training and Consulting
>     https://twitter.com/mtgrigorov
>
>     On Wed, May 3, 2017 at 5:52 PM, Boris Goldowsky <bg...@cast.org>
> wrote:
>
>     > Is there any way to use a method that returns a promise as the
> onBefore of
>     > an IAxaxCallListener?  I don’t want the ajax operation to move
> forward
>     > until the promise resolves.  Due to the nature of promises in
> Javascript,
>     > there doesn’t seem to be a way to simply wait for it.
>     >
>     > Boris
>     >
>     >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: AjaxCallListener and promises

Posted by Boris Goldowsky <bg...@cast.org>.
For anyone who may have a similar issue and find this thread, here’s the workaround I used.

Desired behavior was to have an AJAX submit on a form that includes a drawing widget.  The drawing can’t be saved directly; it needs to be asked to export its data into a hidden text field which can be saved.  The widget’s export operation returns a Promise.

Strategy:

1) Instead of an AjaxSubmit button, I’m using a regular <button>
2) That button has an onclick that invokes the export operation, with a “then” clause that emits a custom javascript event.
3) I attach an AjaxFormSubmitBehavior listening to this custom event, so the form is submitted when the data is ready.

I think it would be a nice feature in the future to think through a reasonable integration of the ajax handlers with Promises, as they are likely to become more commonly used now that they are reasonably standardized.

Boris


On 5/3/17, 3:08 PM, "Martin Grigorov" <mg...@apache.org> wrote:

    Hi,
    
    No, Wicket doesn't use the return values for all handlers but
    "preconditions" [1].
    And even for preconditions the only value that matters is the literal
    *false.*
    
    
    1.
    https://github.com/apache/wicket/blob/b24decd2f60983c11e75e5f2c34d0c6a93b56426/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js#L614
    
    Martin Grigorov
    Wicket Training and Consulting
    https://twitter.com/mtgrigorov
    
    On Wed, May 3, 2017 at 5:52 PM, Boris Goldowsky <bg...@cast.org> wrote:
    
    > Is there any way to use a method that returns a promise as the onBefore of
    > an IAxaxCallListener?  I don’t want the ajax operation to move forward
    > until the promise resolves.  Due to the nature of promises in Javascript,
    > there doesn’t seem to be a way to simply wait for it.
    >
    > Boris
    >
    >
    


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: AjaxCallListener and promises

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

No, Wicket doesn't use the return values for all handlers but
"preconditions" [1].
And even for preconditions the only value that matters is the literal
*false.*


1.
https://github.com/apache/wicket/blob/b24decd2f60983c11e75e5f2c34d0c6a93b56426/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js#L614

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Wed, May 3, 2017 at 5:52 PM, Boris Goldowsky <bg...@cast.org> wrote:

> Is there any way to use a method that returns a promise as the onBefore of
> an IAxaxCallListener?  I don’t want the ajax operation to move forward
> until the promise resolves.  Due to the nature of promises in Javascript,
> there doesn’t seem to be a way to simply wait for it.
>
> Boris
>
>