You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Arjun Dhar <dh...@yahoo.com> on 2011/10/01 20:04:24 UTC

Ajax : Modifying CallBackUrl in OnEvent()

Hi,
I have an overridden the
AbstractDefaultAjaxBehavior.getCallbackScript(boolean onlyTargetActivePage)
method.

I have also overridden the AjaxEventBehavior.onEvent().
In the onEvent(AjaxRequestTarget) I want to re-generate the Callback Script
(replace original one with new one), how can I do that. Once generated am
unable to change it using the target object.

thanks.



-----
Software documentation is like sex: when it is good, it is very, very good; and when it is bad, it is still better than nothing!
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Ajax-Modifying-CallBackUrl-in-OnEvent-tp3863397p3863397.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Ajax : Modifying CallBackUrl in OnEvent()

Posted by Arjun Dhar <dh...@yahoo.com>.
Hi,
I wound a solution/decent work-around to my problem.

So to re-explain it based on what Andrea says:
Yes, its true its too late and there is no pure API way. But there is a work
around.

Problem::
Modify the CallBackUrl for an event based on some condition that may occur
in the event.
Technically speaking, once the callback URL is defined you cannot change it
via the code (official Wicket API imo)


Solution Concepts::
At the end of it, its all JavaScript running, so if we can find a way of
updating the JavaScript on the target we have achieved our goal. The issue
is you dont really want to type all that javascript or hard code it, neither
do you want to create code in bits and pieces that are patched.

Solution Adopted:: (And anyone can fee free to provide a better solution)
Create a new Behavior of the same Class that created the original CallBack.
(Typically this extends AbstractDefaultAjaxBehavior & since you are working
with onEvent() you also implement AjaxEventBehavior). 

Step 1:
Now, In the onEvent(); you create the Behavior based on latest/new
conditions. This Behavior is also capable of giving you the new updated
Javascript without you having to write any JavAscript code.
Like <my Behavior that extends AbstractDefaultAjaxBehavior
>.getCallbackUrl();

Step 2: In the onEvent() add a String updatedCallbackScript = User
JavaScript or JQuery to modify the event attribute of the element and
replace with "new function() {"+newCallbackScript+"}";
(The one line is standard J.Script so its a bit hacky but I guess passable &
standard)

Step 3: In the onEvent() ... add:
target.appendJavascript(updatedCallbackScript);


...and it works!





-----
Software documentation is like sex: when it is good, it is very, very good; and when it is bad, it is still better than nothing!
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Ajax-Modifying-CallBackUrl-in-OnEvent-tp3863397p3892859.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Ajax : Modifying CallBackUrl in OnEvent()

Posted by Andrea Del Bene <ad...@ciseonweb.it>.
Hi,

when onEvent is triggered the callback script has been already executed, 
so it's too late to re-generate it. Maybe I didn't understand right your 
problem.
> Hi,
> I have an overridden the
> AbstractDefaultAjaxBehavior.getCallbackScript(boolean onlyTargetActivePage)
> method.
>
> I have also overridden the AjaxEventBehavior.onEvent().
> In the onEvent(AjaxRequestTarget) I want to re-generate the Callback Script
> (replace original one with new one), how can I do that. Once generated am
> unable to change it using the target object.
>
> thanks.
>
>
>
> -----
> Software documentation is like sex: when it is good, it is very, very good; and when it is bad, it is still better than nothing!
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Ajax-Modifying-CallBackUrl-in-OnEvent-tp3863397p3863397.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>


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