Package org.apache.wicket.util.cookies
Class CookieUtils
java.lang.Object
org.apache.wicket.util.cookies.CookieUtils
Helper class to simplify Cookie handling.
- Author:
- Juergen Donnerstag, Jonathan Locke
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionjakarta.servlet.http.Cookie
Gets the cookie with 'name' attached to the latest WebRequest.protected String
getKey
(FormComponent<?> component) This method gets used when a cookie key needs to be derived from a form component.protected String
getSaveKey
(String key) Make sure the 'key' does not contain any illegal chars.getSessionIdCookieName
(WebApplication application) Gets the name of the cookie where the session id is stored.final CookieDefaults
protected void
initializeCookie
(jakarta.servlet.http.Cookie cookie) Is called before the Cookie is saved.final String
Retrieve the cookie value by means of its key.final String
load
(FormComponent<?> formComponent) Retrieve the cookie value associated with the formComponent and load the model object with the cookie value.final void
Remove the cookie identified by the keyfinal void
remove
(FormComponent<?> formComponent) Remove the cookie identified by the form componentfinal void
Create a Cookie with key and value and save it in the browser with the next responsefinal void
save
(FormComponent<?> formComponent) Save the form components model value in a cookiestatic void
setAttribute
(jakarta.servlet.http.Cookie cookie, String attributeName, String attributeValue) Sets a custom attribute on Servlet 6+
-
Field Details
-
DEFAULT_SESSIONID_COOKIE_NAME
- See Also:
-
-
Constructor Details
-
CookieUtils
public CookieUtils()Construct. -
CookieUtils
Construct.- Parameters:
settings
- the default settings for the saved cookies
-
-
Method Details
-
getSettings
- Returns:
- Gets the settings for these utils
-
remove
Remove the cookie identified by the key- Parameters:
key
- The cookie name
-
remove
Remove the cookie identified by the form component- Parameters:
formComponent
-
-
getKey
This method gets used when a cookie key needs to be derived from a form component. By default the component's page relative path is used.- Parameters:
component
-- Returns:
- cookie key
-
load
Retrieve the cookie value by means of its key.- Parameters:
key
- The cookie name- Returns:
- The cookie value associated with the key
-
load
Retrieve the cookie value associated with the formComponent and load the model object with the cookie value.- Parameters:
formComponent
-- Returns:
- The Cookie value which has also been used to set the component's model value
-
save
Create a Cookie with key and value and save it in the browser with the next response- Parameters:
name
- The cookie namevalue
- The cookie value
-
save
Save the form components model value in a cookie- Parameters:
formComponent
-
-
getSaveKey
Make sure the 'key' does not contain any illegal chars. E.g. for cookies ':' is not allowed.- Parameters:
key
- The key to be validated- Returns:
- The save key
-
getCookie
Gets the cookie with 'name' attached to the latest WebRequest.- Parameters:
name
- The name of the cookie to be looked up- Returns:
- Any cookies for this request
-
getSessionIdCookieName
Gets the name of the cookie where the session id is stored.- Parameters:
application
- The current we application holding theServletContext
.- Returns:
- The name set in
SessionCookieConfig
or the default value 'JSESSIONID' if not set
-
initializeCookie
Is called before the Cookie is saved. May be subclassed for different (dynamic) Cookie parameters. Static parameters can also be changed viaCookieDefaults
.- Parameters:
cookie
-
-
setAttribute
public static void setAttribute(jakarta.servlet.http.Cookie cookie, String attributeName, String attributeValue) Sets a custom attribute on Servlet 6+- Parameters:
cookie
- The cookie to set the attribute onattributeName
- The name of the attributeattributeValue
- The value of the attribute
-