0

I'm trying to set an AbstractAjaxTimerBehavior to start immediately when called and then be repeated every X seconds (let's say 10 seconds), but i couldn't find something. I thought of a hack by setting the first interval to 1 second and then inside onTimer method, set every time the interval to the desired X seconds.

myBehavior = new AbstractAjaxTimerBehavior(Duration.seconds(1)) {

    private static final long serialVersionUID = 1L;

    @Override
    protected void onTimer(AjaxRequestTarget target) {
        this.setUpdateInterval(Duration.seconds(10));
        .
        .
        .
    }
}

Is there a better way of doing that without having to set every time the interval inside onTimer? Thnx!

Artem Shafranov
  • 2,655
  • 19
  • 19
Apostolos
  • 10,033
  • 5
  • 24
  • 39
  • This is one of the two ways I can think of right now. The other would be to use an additional behaviour for the first call. But I'm not completely sure on what you want to archieve as the first call would be issued right after the rendering. In most cases you should be able to supply current data while rendering... – Nicktar Oct 18 '12 at 09:45
  • what i want is to load a GMap object and immediately add some markers that i load from a DB with their lat lng coords. then, after the normal interval (10 seconds) their position would be changed and displayed at map. – Apostolos Oct 18 '12 at 10:27
  • 1
    If you "pull" your values from the model rather than pushing them into your model in the `onTimer()` method (which I suspect you're doing), you should get the correct behaviour. – biziclop Oct 18 '12 at 12:46
  • yes. this is another "trick" that we load what we want before attaching the behavior to the component we want. so in a way we duplicate the code inside the onTimer method before attaching the behavior (if i understood correctly). – Apostolos Oct 18 '12 at 15:46

0 Answers0