You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Maris Orbidans <ma...@ingg.com> on 2010/10/13 13:37:04 UTC

condition in AbstractAjaxTimerBehavior

Hi

I need to periodically update a page unless some condition is met.
I wrote javascript function canRefresh() and added like this:

add(new AbstractAjaxTimerBehavior(Duration.seconds(5)) {
  @Override
  protected void onTimer(final AjaxRequestTarget target) {
    updateSessionConfigPanel(target);
   }

   @Override
    protected CharSequence getCallbackScript() {
      return "if (!canRefresh()) {"+ super.getCallbackScript()+"};";
      }
 });

This is generated javascript.

<script type="text/javascript" ><!--/*--><![CDATA[/*><!--*/
Wicket.Event.add(window, "load", function(event) { setTimeout("if
(!canRefresh()) {var
wcall=wicketAjaxGet('?wicket:interface=:0::IActivePageBehaviorListener:1
:&wicket:ignoreIfNotActive=true',function() { }.bind(this),function() {
}.bind(this));};", 5000);;});
/*-->]]>*/</script>

The problem is that once canRefresh() returns false timer stops. Is it
possible to restart it?  Or a better way to implement conditional
update?


Maris

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


Re: condition in AbstractAjaxTimerBehavior

Posted by Igor Vaynberg <ig...@gmail.com>.
if (!canrefresh()) { settimeout( <add original script )} else {
<original script> }


-igor

On Wed, Oct 13, 2010 at 4:37 AM, Maris Orbidans <ma...@ingg.com> wrote:
> Hi
>
> I need to periodically update a page unless some condition is met.
> I wrote javascript function canRefresh() and added like this:
>
> add(new AbstractAjaxTimerBehavior(Duration.seconds(5)) {
>  @Override
>  protected void onTimer(final AjaxRequestTarget target) {
>    updateSessionConfigPanel(target);
>   }
>
>   @Override
>    protected CharSequence getCallbackScript() {
>      return "if (!canRefresh()) {"+ super.getCallbackScript()+"};";
>      }
>  });
>
> This is generated javascript.
>
> <script type="text/javascript" ><!--/*--><![CDATA[/*><!--*/
> Wicket.Event.add(window, "load", function(event) { setTimeout("if
> (!canRefresh()) {var
> wcall=wicketAjaxGet('?wicket:interface=:0::IActivePageBehaviorListener:1
> :&wicket:ignoreIfNotActive=true',function() { }.bind(this),function() {
> }.bind(this));};", 5000);;});
> /*-->]]>*/</script>
>
> The problem is that once canRefresh() returns false timer stops. Is it
> possible to restart it?  Or a better way to implement conditional
> update?
>
>
> Maris
>
> ---------------------------------------------------------------------
> 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