user182944
user182944

Reputation: 8067

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,

Upvotes: 1

Views: 1529

Answers (2)

CatSleeping
CatSleeping

Reputation: 91

The Flash scope is devised to solve data exchanging problem that occurs when we redirect a JSF page to another.

Two requests are generated during redirecting JSF page. The first request is the post-back to the source JSF page. The second request is the initial request to the target JSF page. The objects in the request scope in the first scope are cleared in the second request.

To overcome this problem, use the Flash scope to exchange data when redirecting to another JSF page.

See more:

Upvotes: 0

PermGenError
PermGenError

Reputation: 46438

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.

Upvotes: 1

Related Questions