public static final class H.Flash extends H.KV<H.Flash>
A Flash represent a storage scope that attributes inside is valid only for one session interaction. This feature of flash makes it very good for server to pass one time information to client, e.g. form submission error message etc.
Like H.Session
, you can store only String type
information to flash, and the total number of information stored
including keys and values shall not exceed 4096 bytes as flash is
persisted as cookie in browser
Constructor and Description |
---|
H.Flash() |
Modifier and Type | Method and Description |
---|---|
static H.Flash |
current()
Return a flash instance of the current execution context, For example from a
ThreadLocal |
static void |
current(H.Flash flash)
Set a flash instance into the current execution context, for example into a
ThreadLocal |
H.Flash |
discard()
Discard the whole output buffer of the flash but the data buffer is remain untouched.
|
H.Flash |
discard(String key)
Discard a data from the output buffer of the flash but the data buffer is remain untouched.
|
boolean |
equals(Object obj) |
String |
error()
Get the “error” message that has been added to the flash scope.
|
H.Flash |
error(String message)
Add an “error” message to the flash scope
|
H.Flash |
error(String message,
Object... args)
Add an “error” message to the flash scope, with optional format arguments
|
H.Flash |
keep()
Keep all data that has been
put into the flash for one time. |
H.Flash |
keep(String key)
Keep a data that has been
put into the flash for one time. |
H.Flash |
now(String key,
String value)
Add an attribute to the flash’s current scope.
|
H.KV |
out() |
H.Flash |
put(String key,
Object value)
Add an attribute to the flash scope.
|
H.Flash |
put(String key,
String value)
Add an attribute to the flash scope.
|
static H.Flash |
resolve(H.Cookie flashCookie)
Resolve a Flash instance from a cookie.
|
H.Cookie |
serialize(String flashKey)
Serialize this Flash instance into a Cookie.
|
String |
success()
Get the “success” message that has been added to the flash scope.
|
H.Flash |
success(String message)
Add a “success” message to the flash scope
|
H.Flash |
success(String message,
Object... args)
Add a “success” message to the flash scope, with optional format arguments
|
public H.Flash put(String key, String value)
Add an attribute to the flash scope. The data is added to both data buffer and the out buffer
public H.Flash put(String key, Object value)
Add an attribute to the flash scope. The value is in Object type, however it will be convert to its string
representation
before put into the flash
public H.Flash now(String key, String value)
Add an attribute to the flash’s current scope. Meaning when next time the user request to the server, the attribute will not be there anymore.
key
- the attribute keyvalue
- the attribute valuepublic H.Flash error(String message)
Add an “error” message to the flash scope
message
- the error messageput(String, Object)
public H.Flash error(String message, Object... args)
Add an “error” message to the flash scope, with optional format arguments
message
- the message templateargs
- the format argumentspublic String error()
Get the “error” message that has been added to the flash scope.
null
if no error message has been added to the flashpublic H.Flash success(String message)
Add a “success” message to the flash scope
message
- the error messageput(String, Object)
public H.Flash success(String message, Object... args)
Add a “success” message to the flash scope, with optional format arguments
message
- the message templateargs
- the format argumentspublic String success()
Get the “success” message that has been added to the flash scope.
null
if no success message has been added to the flashpublic H.Flash discard(String key)
Discard a data from the output buffer of the flash but the data buffer is remain untouched. Meaning the app can still get the data put(String, Object)
into the flash scope, however they will NOT be write to the client cookie, thus the next time client request the server, the app will not be able to get the info anymore
key
- the key to the data to be discardedpublic H.Flash discard()
Discard the whole output buffer of the flash but the data buffer is remain untouched. Meaning the app can still get the data put(String, Object)
into the flash scope, however they will NOT be write to the client cookie, thus the next time client request the server, the app will not be able to get those info anymore
public H.Flash keep(String key)
Keep a data that has been put
into the flash for one time. The data that has been kept will be persistent to client cookie for one time, thus the next time when user request the server, the app can still get the data, but only for one time unless the app call keep
method again
key
- the key to identify the data to be keptkeep()
public H.Flash keep()
Keep all data that has been put
into the flash for one time. The data that has been kept will be persistent to client cookie for one time, thus the next time when user request the server, the app can still get the data, but only for one time unless the app call keep
method again
public H.KV out()
public static H.Flash current()
Return a flash instance of the current execution context, For example from a ThreadLocal
public static void current(H.Flash flash)
Set a flash instance into the current execution context, for example into a ThreadLocal
flash
- the flash to be set to current execution contextpublic static H.Flash resolve(H.Cookie flashCookie)
Resolve a Flash instance from a cookie. If the cookie supplied is null
then an empty Flash instance is returned
flashCookie
- the flash cookieserialize(String)
public H.Cookie serialize(String flashKey)
Serialize this Flash instance into a Cookie. Note the cookie returned has only name, value and max Age been set. It’s up to the caller to set secure, path and httpOnly attributes.
flashKey
- the cookie nameresolve(org.osgl.http.H.Cookie)
Copyright © 2017–2020 OSGL (Open Source General Library). All rights reserved.