javaplayframeworkplayframework-1.x

Difference between Flash Scope and Request Scope


What is the difference between Flash Scope and View Scope?

Can someone please explain it with an example?

Regards,


Solution

  • Flash Scope From the DOC:

    The Flash scope works exactly like the Session, but with two differences: data are kept for only one request the Flash cookie is not signed, making it possible for the user to modify it.

    Example:

    public static Result index() {
      String message = flash("success");
      if(message == null) {
        message = "Welcome!";
      }
      return ok(message);
    }
    
    public static Result save() {
      flash("success", "The item has been created");
      return redirect("/home");
    }
    

    Request Scope is straight forward, it exists for a particular request only.