You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by infiniter <in...@gmail.com> on 2013/03/14 22:55:21 UTC

AbstractAjaxTimerBehavior and setInterval and clearInterval

I created a very similar class to AbstractAjaxTimerBehavior, with the
difference that I'm using setInterval instead of setTimeOut in
#getJsTimeoutCall and I'm assigning a variable name to it, so that I can use
the clearInterval in #getFailureScript , the problem I got is that in the
response envelope I'm getting the script in #getJsTimeoutCall back, which is
inside the <evaluate> block, and I don't want that because when the
setInterval is set again the value in the variable changes therefore I
cannot clear the interval and also it makes the response heavier.

So basically I just want the script in #getJsTimeoutCall executed only once
just to start the interval. I tried to make the response not return the
"evaluate" block,  but I was unsuccessful.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/AbstractAjaxTimerBehavior-and-setInterval-and-clearInterval-tp4657268.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: AbstractAjaxTimerBehavior and setInterval and clearInterval

Posted by infiniter <in...@gmail.com>.
ok, that was already implemented: 
*   	
      public void renderHead(IHeaderResponse response){
   		super.renderHead(response);
   		WebRequest request = (WebRequest) RequestCycle.get().getRequest();
   		if (!stopped && (!headRendered || !request.isAjax())) {
   			headRendered = true;
   			response.renderOnLoadJavascript(getJsTimeoutCall(updateInterval));
   		}
   	}
*

(btw, I tried with response.renderOnDomReady)
I also tried making the #respond method just do target.add(getComponent())
 
But my problem is that in each response the same script that was first
loaded is also returned back in the evaluate block, which rewrites the
interval variable and also makes the response much heavier (in my case the
requests are very frequent)

I traced my issue to #AjaxRequestTarget.respond and the following piece of
code makes sure that the js passed to response.renderOnDomReady in my
#renderHead will always be returned back in the response:
*   	
		it = domReadyJavascripts.iterator();
		while (it.hasNext())
			String js = it.next();
			respondInvocation(response, js);
		}
*

Any ideas are appreciated.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/AbstractAjaxTimerBehavior-and-setInterval-and-clearInterval-tp4657268p4657282.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: AbstractAjaxTimerBehavior and setInterval and clearInterval

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

I'm not sure how your logic looks like but the simplest solution that I see
is to use a member boolean variable 'hasRendered' in your behavior and use
it in #renderHead() so that the JS is contributed just once.

if (!hasRendered) {
   hasRendered = true;
   response.render(OnDomReadyHeaderItem.forScript(....));
}


On Thu, Mar 14, 2013 at 10:55 PM, infiniter <in...@gmail.com> wrote:

> I created a very similar class to AbstractAjaxTimerBehavior, with the
> difference that I'm using setInterval instead of setTimeOut in
> #getJsTimeoutCall and I'm assigning a variable name to it, so that I can
> use
> the clearInterval in #getFailureScript , the problem I got is that in the
> response envelope I'm getting the script in #getJsTimeoutCall back, which
> is
> inside the <evaluate> block, and I don't want that because when the
> setInterval is set again the value in the variable changes therefore I
> cannot clear the interval and also it makes the response heavier.
>
> So basically I just want the script in #getJsTimeoutCall executed only once
> just to start the interval. I tried to make the response not return the
> "evaluate" block,  but I was unsuccessful.
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/AbstractAjaxTimerBehavior-and-setInterval-and-clearInterval-tp4657268.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
>
>


-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>