Package ninja.session
Class FlashScopeImpl
- java.lang.Object
-
- ninja.session.FlashScopeImpl
-
- All Implemented Interfaces:
FlashScope
public class FlashScopeImpl extends Object implements FlashScope
Default FlashScope implementation.
-
-
Constructor Summary
Constructors Constructor Description FlashScopeImpl(NinjaProperties ninjaProperties)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearCurrentFlashCookieData()Clears all "current" flash data.booleancontains(String key)Checks if the key exists in the "current" flash data.voiddiscard()Discards all "outgoing" flash data but retains all "current" flash data.voiddiscard(String key)Discards the key from the "outgoing" flash data but retains it in the "current" flash data.voiderror(String value)Same as callingflash.put("error", "your value");.Stringget(String key)Gets a value if its in either the "current" or "outgoing" flash data.Map<String,String>getCurrentFlashCookieData()Gets all "current" flash data.Map<String,String>getOutgoingFlashCookieData()Gets all "outgoing" flash data.voidinit(Context context)Intended for use by implementations only.voidkeep()Copies all "current" flash data into the "outgoing" flash data.voidkeep(String key)Will copy the "current" flash data specified by the key into the "outgoing" flash data.voidnow(String key, String value)Puts the key and value into only the "current" flash data.voidput(String key, Object value)voidput(String key, String value)Puts the key and value into both "current" and "outgoing" flash data.booleanremove(String key)Removes a value completely from both "current" and "outgoing" flash data.voidsave(Context context)Intended for use by implementations only.voidsuccess(String value)Same as callingflash.put("success", "your value");.
-
-
-
Constructor Detail
-
FlashScopeImpl
@Inject public FlashScopeImpl(NinjaProperties ninjaProperties)
-
-
Method Detail
-
init
public void init(Context context)
Description copied from interface:FlashScopeIntended for use by implementations only. Initializes the FlashScope from the context. Ninja will call this when a new request is being handled.- Specified by:
initin interfaceFlashScope- Parameters:
context- The Ninja context
-
save
public void save(Context context)
Description copied from interface:FlashScopeIntended for use by implementations only. Saves the FlashScope to the context. Will write/delete cookies, etc. Ninja will call this when a request will be completed.- Specified by:
savein interfaceFlashScope- Parameters:
context- The Ninja context
-
now
public void now(String key, String value)
Description copied from interface:FlashScopePuts the key and value into only the "current" flash data. Will NOT be written as a cookie and will only exist for the current request. Accessible via ${flash.key} in your html templating engine.- Specified by:
nowin interfaceFlashScope- Parameters:
key- The flash keyvalue- The i18n key used to retrieve value of that message OR an already translated message (if your template engine supports it)- See Also:
If you need the value for both the current and next request
-
get
public String get(String key)
Description copied from interface:FlashScopeGets a value if its in either the "current" or "outgoing" flash data.- Specified by:
getin interfaceFlashScope- Parameters:
key- The flash key- Returns:
- The flash value or null if none exists by that key
-
remove
public boolean remove(String key)
Description copied from interface:FlashScopeRemoves a value completely from both "current" and "outgoing" flash data.- Specified by:
removein interfaceFlashScope- Parameters:
key- The flash key- Returns:
- True if removed or false if it didn't exist
-
contains
public boolean contains(String key)
Description copied from interface:FlashScopeChecks if the key exists in the "current" flash data.- Specified by:
containsin interfaceFlashScope- Parameters:
key- The flash key- Returns:
- True if the key exists or false if it doesn't
-
put
public void put(String key, String value)
Description copied from interface:FlashScopePuts the key and value into both "current" and "outgoing" flash data. Will be written as a cookie and available in the current and next request. If you only need the value in your current request its a good idea to use thenow()method instead so you can eliminate the possibility of showing unexpected flash messages on the next request :-).- Specified by:
putin interfaceFlashScope- Parameters:
key- The flash keyvalue- The i18n key used to retrieve value of that message OR an already translated message (if your template engine supports it)- See Also:
If you only need the value in your current request.
-
put
public void put(String key, Object value)
- Specified by:
putin interfaceFlashScope
-
error
public void error(String value)
Description copied from interface:FlashScopeSame as callingflash.put("error", "your value");. The value will be added to both "current" and "outgoing" flash data.- Specified by:
errorin interfaceFlashScope- Parameters:
value- The i18n key used to retrieve value of that message OR an already translated message (if your template engine supports it)
-
success
public void success(String value)
Description copied from interface:FlashScopeSame as callingflash.put("success", "your value");. The value will be added to both "current" and "outgoing" flash data.- Specified by:
successin interfaceFlashScope- Parameters:
value- The i18n key used to retrieve value of that message OR an already translated message (if your template engine supports it)
-
discard
public void discard(String key)
Description copied from interface:FlashScopeDiscards the key from the "outgoing" flash data but retains it in the "current" flash data.- Specified by:
discardin interfaceFlashScope- Parameters:
key- The flash key- See Also:
To reverse this operation and keep the key as part of the "outgoing" flash data.
-
discard
public void discard()
Description copied from interface:FlashScopeDiscards all "outgoing" flash data but retains all "current" flash data.- Specified by:
discardin interfaceFlashScope- See Also:
To reverse this operation and keep all keys as part of the "outgoing" flash data.
-
keep
public void keep(String key)
Description copied from interface:FlashScopeWill copy the "current" flash data specified by the key into the "outgoing" flash data.- Specified by:
keepin interfaceFlashScope- Parameters:
key- The flash key
-
keep
public void keep()
Description copied from interface:FlashScopeCopies all "current" flash data into the "outgoing" flash data.- Specified by:
keepin interfaceFlashScope
-
clearCurrentFlashCookieData
public void clearCurrentFlashCookieData()
Description copied from interface:FlashScopeClears all "current" flash data. If you need to ensure all "current" and "outgoing" flash data is deleted then call this as well as discard().- Specified by:
clearCurrentFlashCookieDatain interfaceFlashScope
-
getCurrentFlashCookieData
public Map<String,String> getCurrentFlashCookieData()
Description copied from interface:FlashScopeGets all "current" flash data.- Specified by:
getCurrentFlashCookieDatain interfaceFlashScope- Returns:
- All current flash data
-
getOutgoingFlashCookieData
public Map<String,String> getOutgoingFlashCookieData()
Description copied from interface:FlashScopeGets all "outgoing" flash data.- Specified by:
getOutgoingFlashCookieDatain interfaceFlashScope- Returns:
- All outgoing flash data
-
-