Currently learning play! 2.0, I wanted to add an "opening" to my homepage : the first time a user connects to the homepage, an opening would display for a few seconds and then he would be automatically redirected to the real home page. This opening would not be shown again for the rest of the session.

For now that piece of code looks like :

public class Application extends Controller {

private static ScheduledExecutorService executor = executors.newSingleThreadScheduledExecutor();

public static Result home() {
    boolean introSeen = Cache.get("introSeen") == null ? false : true;
    if(introSeen) {
        System.out.println("Cache good, sending you home !");
        return ok(home.render(Configs.HOME));
        //return redirect("/");
    }
    else {
        Cache.set("introSeen", true, 2*60*60);
        Runnable task = new Runnable(){

            @Override
            public void run() {
                home();
                executor.shutdown();
            }
        };
        executor.schedule(task, 7, TimeUnit.SECONDS);
        return ok(intro.render(Configs.HOME));
    }
}

I've added the println to make sure the cache variable registration and the delayed task were working, and they do. But for an unknown reason, the code

return ok(home.render(Configs.HOME));

is not working and the intro view (intro) stays on screen.

I've tried to user redirect instead of "ok" too, but nothing so far.

Thanks for your help :)

有帮助吗?

解决方案

Why don't you just use Meta refresh or some JavaScript technique to do that ?

You can use session cookie for checking if next time user should see the opening or target page.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top