O'Reilly logo

Play Framework Cookbook - Second Edition by Giancarlo Inductivo, Alexander Reelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using custom actions

For this recipe, we will explore how Play Framework provides the building blocks for creating reusable, custom actions.

How to do it…

For Java, we need to take the following steps:

  1. Run the foo_java application with Hot-Reloading enabled.
  2. Modify foo_java/app/controllers/Application.java by adding the following action:
        @With(AuthAction.class)
        public static Result dashboard() {
            return ok("User dashboard");
        }
    
        public static Result login() {
            return ok("Please login");
        }
  3. Add our new action class to foo_java/app/controllers/AuthAction.java as well:
    package controllers; import play.*; import play.mvc.*; import play.libs.*; import play.libs.F.*; public class AuthAction extends play.mvc.Action.Simple { public F.Promise<Result> call(Http.Context ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required