Hi Daniel,
Tapestry does not process objects created using new. You can however try to
use ObjectLocator service. For example:

public class MyPage {

 @Inject private ObjectLocator locator;



.... inside some method ...

Timer timer = new Timer("MyTimer");
OurTimerTask timerTask = locator.autobuild(OurTimerTask.class);
timer.schedule(timerTask, 100,100);

}

Alternatively, you can implement a factory service that would just create
OurTimerTask instances and provide them with a reference to OurService.

Cezary
On Thu, Jul 26, 2012 at 5:24 PM, Stammler, Daniel
<daniel.stamm...@sap.com>wrote:

> Hello,
>
> we have some problems with the periodical execution of a function. We're
> using tapestry version 5.2.6. Since we don't want to update the tapestry
> version right now, we can not use the tapestry timer and have to use the
> Java Timer.
>
> Our timertask looks like:
>
> public class OurTimerTask extends TimerTask {
> @Inject
> OurService ourService;
>
>         @Override
>         public void run() {
>                 ourService.execute();
>
>         }
> }
>
> And the service that starts the timer:
>
> Timer timer = new Timer("MyTimer");
> OurTimerTask timerTask = new OurTimerTask();
>
>                 // its the date of the first execution. It should be in
> the night of the
>                 // current day
>
> timer.schedule(timerTask, 100,100);
>
> The problem now is that the Inject in our TimerTask doesn't work. We tried
> this in many ways but the object ourService is always null if the run()
> function gets called. Without the Timer it works. Is it even possible to
> Inject a service for the timer? We hope that anyone can help us.
>
> Kind regards
> Daniel
>
>

Reply via email to