Package play.mvc
Class Result
java.lang.Object
play.mvc.Result
- Direct Known Subclasses:
StatusHeader
Any action result.
-
Constructor Summary
ConstructorsConstructorDescriptionResult(int status) Create a result with no entity.Create a result.Create a result with no body.Result(int status, Map<String, String> headers, HttpEntity body) Create a result.Result(int status, HttpEntity body) Create a result.Result(ResponseHeader header, HttpEntity body) Create a result from a Scala ResponseHeader and a body.Result(ResponseHeader header, HttpEntity body, Http.Session session, Http.Flash flash, List<Http.Cookie> cookies) Create a result from a Scala ResponseHeader and a body.Result(ResponseHeader header, HttpEntity body, Http.Session session, Http.Flash flash, List<Http.Cookie> cookies, TypedMap attrs) Create a result from a Scala ResponseHeader and a body. -
Method Summary
Modifier and TypeMethodDescription<A> ResultCreate a new versions of this object with the given attribute attached to it.addAttrs(List<TypedEntry<?>> entries) Create a new versions of this object with the given attributes attached to it.addAttrs(TypedEntry<?> e1) Create a new versions of this object with the given attribute attached to it.addAttrs(TypedEntry<?>... entries) Create a new versions of this object with the given attributes attached to it.addAttrs(TypedEntry<?> e1, TypedEntry<?> e2) Create a new versions of this object with the given attributes attached to it.addAttrs(TypedEntry<?> e1, TypedEntry<?> e2, TypedEntry<?> e3) Create a new versions of this object with the given attributes attached to it.addingToSession(Http.Request request, String key, String value) Adds the given key and value to the session.addingToSession(Http.Request request, Map<String, String> values) Adds values to the session.Return a copy of the result with a different Content-Type header.play.api.mvc.ResultasScala()Convert this result to a Scala result.attrs()body()Get the body of this result.charset()Extracts the Charset of this Result value.Extracts the Content-Type of this Result value.Extracts a Cookie value from this Result valuecookies()Extracts the Cookies (an iterator) from this result value.discardingCookie(String name) Discard a cookie on the default path ("/") with no domain and that's not secure.discardingCookie(String name, String path) Discard a cookie on the given path with no domain and not that's secure.discardingCookie(String name, String path, String domain) Discard a cookie on the given path and domain that's not secure.discardingCookie(String name, String path, String domain, boolean secure) Discard a cookie in this resultdiscardingCookie(String name, String path, String domain, boolean secure, Http.Cookie.SameSite sameSite) Discard a cookie in this resultflash()Extracts the Flash values of this Result value.Adds the given key and value to the flash.Adds values to the flash.Deprecated.Deprecated as of 2.8.0.protected ResponseHeaderGet the response headerExtracts an Header value of this Result value.headers()Extracts all Headers of this Result value.Get the reason phrase, if it was set.Extracts the Location header of this Result value if this Result is a Redirect.removeAttr(TypedKey<?> key) Create a new versions of this object with the given attribute removed.removingFromFlash(String... keys) Removes values from the flash.removingFromSession(Http.Request request, String... keys) Removes values from the session.session()Extracts the Session of this Result value.session(Http.Request request) intstatus()Get the status.Create a new version of this object with the given attributes attached to it.withCookies(Http.Cookie... newCookies) Returns a copy of this result with the given cookies.Sets a new flash for this result, discarding the existing flash.withFlash(Http.Flash flash) Sets a new flash for this result, discarding the existing flash.withHeader(String name, String value) Return a copy of this result with the given header.withHeaders(String... nameValues) Return a copy of this result with the given headers.withLang(Locale locale, MessagesApi messagesApi) Returns a new result with the given lang set in a cookie.withLang(Lang lang, MessagesApi messagesApi) Returns a new result with the given lang set in a cookie.Discards the existing flash for this result.Discards the existing session for this result.withoutHeader(String name) Discard a HTTP header in this result.withoutLang(MessagesApi messagesApi) Clears the lang cookie from this result.withSession(Map<String, String> session) Sets a new session for this result, discarding the existing session.withSession(Http.Session session) Sets a new session for this result, discarding the existing session.
-
Constructor Details
-
Result
public Result(ResponseHeader header, HttpEntity body, Http.Session session, Http.Flash flash, List<Http.Cookie> cookies, TypedMap attrs) Create a result from a Scala ResponseHeader and a body.- Parameters:
header- the response headerbody- the response body.session- the session set on the response.flash- the flash object on the response.cookies- the cookies set on the response.attrs- the typed attributes set on the response.
-
Result
public Result(ResponseHeader header, HttpEntity body, Http.Session session, Http.Flash flash, List<Http.Cookie> cookies) Create a result from a Scala ResponseHeader and a body.- Parameters:
header- the response headerbody- the response body.session- the session set on the response.flash- the flash object on the response.cookies- the cookies set on the response.
-
Result
Create a result from a Scala ResponseHeader and a body.- Parameters:
header- the response headerbody- the response body.
-
Result
Create a result.- Parameters:
status- The status.reasonPhrase- The reason phrase, if a non default reason phrase is required.headers- The headers.body- The body.
-
Result
Create a result.- Parameters:
status- The status.headers- The headers.body- The body.
-
Result
Create a result with no body.- Parameters:
status- The status.headers- The headers.
-
Result
Create a result.- Parameters:
status- The status.body- The entity.
-
Result
public Result(int status) Create a result with no entity.- Parameters:
status- The status.
-
-
Method Details
-
status
public int status()Get the status.- Returns:
- the status
-
reasonPhrase
Get the reason phrase, if it was set.- Returns:
- the reason phrase (e.g. "NOT FOUND")
-
getHeader
Get the response header- Returns:
- the header
-
body
Get the body of this result.- Returns:
- the body
-
redirectLocation
Extracts the Location header of this Result value if this Result is a Redirect.- Returns:
- the location (if it was set)
-
header
Extracts an Header value of this Result value.- Parameters:
header- the header name.- Returns:
- the header (if it was set)
-
headers
Extracts all Headers of this Result value.The returned map is not modifiable.
- Returns:
- the immutable map of headers
-
contentType
Extracts the Content-Type of this Result value.- Returns:
- the content type (if it was set)
-
charset
Extracts the Charset of this Result value.- Returns:
- the charset (if it was set)
-
flash
Extracts the Flash values of this Result value.- Returns:
- the flash (if it was set)
-
withFlash
Sets a new flash for this result, discarding the existing flash.- Parameters:
flash- the flash to set with this result- Returns:
- the new result
-
withFlash
Sets a new flash for this result, discarding the existing flash.- Parameters:
flash- the flash to set with this result- Returns:
- the new result
-
withNewFlash
Discards the existing flash for this result.- Returns:
- the new result
-
flashing
Adds values to the flash.- Parameters:
values- A map with values to add to this result's flash- Returns:
- A copy of this result with values added to its flash scope.
-
flashing
Adds the given key and value to the flash.- Parameters:
key- The key to add to this result's flashvalue- The value to add to this result's flash- Returns:
- A copy of this result with the key and value added to its flash scope.
-
removingFromFlash
Removes values from the flash.- Parameters:
keys- Keys to remove from flash- Returns:
- A copy of this result with keys removed from its flash scope.
-
session
Extracts the Session of this Result value.- Returns:
- the session (if it was set)
-
session
- Parameters:
request- Current request- Returns:
- The session carried by this result. Reads the given request's session if this result does not has a session.
-
withSession
Sets a new session for this result, discarding the existing session.- Parameters:
session- the session to set with this result- Returns:
- the new result
-
withSession
Sets a new session for this result, discarding the existing session.- Parameters:
session- the session to set with this result- Returns:
- the new result
-
withNewSession
Discards the existing session for this result.- Returns:
- the new result
-
addingToSession
Adds values to the session.- Parameters:
values- A map with values to add to this result's session- Returns:
- A copy of this result with values added to its session scope.
-
addingToSession
Adds the given key and value to the session.- Parameters:
key- The key to add to this result's sessionvalue- The value to add to this result's session- Returns:
- A copy of this result with the key and value added to its session scope.
-
removingFromSession
Removes values from the session.- Parameters:
keys- Keys to remove from session- Returns:
- A copy of this result with keys removed from its session scope.
-
cookie
Extracts a Cookie value from this Result value- Parameters:
name- the cookie's name.- Returns:
- the optional cookie
-
getCookie
Deprecated.Deprecated as of 2.8.0. Renamed tocookie(String)Extracts a Cookie value from this Result value- Parameters:
name- the cookie's name.- Returns:
- the optional cookie
-
cookies
Extracts the Cookies (an iterator) from this result value.- Returns:
- the cookies (if they were set)
-
withCookies
Returns a copy of this result with the given cookies.- Parameters:
newCookies- the cookies to add to the result.- Returns:
- the transformed copy.
-
discardingCookie
Discard a cookie on the default path ("/") with no domain and that's not secure.- Parameters:
name- The name of the cookie to discard, must not be null
-
discardingCookie
Discard a cookie on the given path with no domain and not that's secure.- Parameters:
name- The name of the cookie to discard, must not be nullpath- The path of the cookie to discard, may be null
-
discardingCookie
Discard a cookie on the given path and domain that's not secure.- Parameters:
name- The name of the cookie to discard, must not be nullpath- The path of the cookie te discard, may be nulldomain- The domain of the cookie to discard, may be null
-
discardingCookie
Discard a cookie in this result- Parameters:
name- The name of the cookie to discard, must not be nullpath- The path of the cookie te discard, may be nulldomain- The domain of the cookie to discard, may be nullsecure- Whether the cookie to discard is secure
-
discardingCookie
public Result discardingCookie(String name, String path, String domain, boolean secure, Http.Cookie.SameSite sameSite) Discard a cookie in this result- Parameters:
name- The name of the cookie to discard, must not be nullpath- The path of the cookie te discard, may be nulldomain- The domain of the cookie to discard, may be nullsecure- Whether the cookie to discard is securesameSite- The SameSite attribute of the cookie to discard, may be null
-
withHeader
Return a copy of this result with the given header.- Parameters:
name- the header namevalue- the header value- Returns:
- the transformed copy
-
withHeaders
Return a copy of this result with the given headers.The headers are processed in pairs, so nameValues(0) is the first header's name, and nameValues(1) is the first header's value, nameValues(2) is second header's name, and so on.
- Parameters:
nameValues- the array of names and values.- Returns:
- the transformed copy
-
withoutHeader
Discard a HTTP header in this result.- Parameters:
name- the header name- Returns:
- the transformed copy
-
as
Return a copy of the result with a different Content-Type header.- Parameters:
contentType- the content type to set- Returns:
- the transformed copy
-
withLang
Returns a new result with the given lang set in a cookie. For example:
Wherepublic Result action() { ok("Hello").withLang(Lang.forCode("es"), messagesApi); }messagesApiwere injected.- Parameters:
lang- the new langmessagesApi- the messages api implementation- Returns:
- a new result with the given lang.
- See Also:
-
withLang
Returns a new result with the given lang set in a cookie. For example:
Wherepublic Result action() { ok("Hello").withLang(new Locale("es"), messagesApi); }messagesApiwere injected.- Parameters:
locale- the new langmessagesApi- the messages api implementation- Returns:
- a new result with the given lang.
- See Also:
-
withoutLang
Clears the lang cookie from this result. For example:
Wherepublic Result action() { ok("Hello").withoutLang(messagesApi); }messagesApiwere injected.- Parameters:
messagesApi- the messages api implementation- Returns:
- a new result without the lang
- See Also:
-
attrs
- Returns:
- a map of typed attributes associated with the result.
-
withAttrs
Create a new version of this object with the given attributes attached to it.- Parameters:
newAttrs- The new attributes to add.- Returns:
- The new version of this object with the attributes attached.
-
addAttr
Create a new versions of this object with the given attribute attached to it.- Type Parameters:
A- the attribute type- Parameters:
key- The new attribute key.value- The attribute value.- Returns:
- The new version of this object with the new attribute.
-
addAttrs
Create a new versions of this object with the given attribute attached to it.- Parameters:
e1- The new attribute.- Returns:
- The new version of this object with the new attribute.
-
addAttrs
Create a new versions of this object with the given attributes attached to it.- Parameters:
e1- The first new attribute.e2- The second new attribute.- Returns:
- The new version of this object with the new attributes.
-
addAttrs
Create a new versions of this object with the given attributes attached to it.- Parameters:
e1- The first new attribute.e2- The second new attribute.e3- The third new attribute.- Returns:
- The new version of this object with the new attributes.
-
addAttrs
Create a new versions of this object with the given attributes attached to it.- Parameters:
entries- The new attributes.- Returns:
- The new version of this object with the new attributes.
-
addAttrs
Create a new versions of this object with the given attributes attached to it.- Parameters:
entries- The new attributes.- Returns:
- The new version of this object with the new attributes.
-
removeAttr
Create a new versions of this object with the given attribute removed.- Parameters:
key- The key of the attribute to remove.- Returns:
- The new version of this object with the attribute removed.
-
asScala
public play.api.mvc.Result asScala()Convert this result to a Scala result.- Returns:
- the Scala result.
-