Class Value
- java.lang.Object
-
- com.adobe.granite.ui.components.Value
-
public class Value extends java.lang.Object
A helper for the form field to access theFormData
.To set the FormData, one of the following can be used (ordered by priority):
- Set the request attribute using
FormData.push(SlingHttpServletRequest, ValueMap, NameNotFoundMode)
- Set the request attribute using
FORM_VALUESS_ATTRIBUTE
as the key - Set the request attribute using
CONTENTPATH_ATTRIBUTE
as the key
- Set the request attribute using
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CONTENTPATH_ATTRIBUTE
Deprecated.static java.lang.String
FORM_VALUESS_ATTRIBUTE
Deprecated.
-
Constructor Summary
Constructors Constructor Description Value(SlingHttpServletRequest request, Config config)
Instantiates a new Value.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
get(java.lang.String name)
A shortcut toget(String, Object)
, with empty string as default value.<T> T
get(java.lang.String name, java.lang.Class<T> type)
Returns the value for the given name, converted to type T.<T> T
get(java.lang.String name, T defaultValue)
Returns the value for the given name, converted to type T.java.lang.String
getContentValue(java.lang.String name)
A shortcut togetContentValue(String, Object)
, with empty string as default value.<T> T
getContentValue(java.lang.String name, java.lang.Class<T> type)
Returns value from the given name, converted to the given type.<T> T
getContentValue(java.lang.String name, T defaultValue)
Returns value from the given name, converted to the type of given default value.boolean
isSelected(java.lang.String value, boolean isFieldOptionSelected)
A shortcut ofisSelected(String, String, boolean)
, with name is taken fromname
property of the config.boolean
isSelected(java.lang.String value, boolean isFieldOptionSelected, boolean forceIgnoreFreshness)
A shortcut ofisSelected(String, String, boolean, boolean)
, with name is taken fromname
property of the config.boolean
isSelected(java.lang.String name, java.lang.String value, boolean isFieldOptionSelected)
boolean
isSelected(java.lang.String name, java.lang.String value, boolean isFieldOptionSelected, boolean forceIgnoreFreshness)
Returnstrue
if the given value of the field option is selected;false
otherwise.<T> T
val(java.lang.String name, T fieldValue)
Returns the value for the given name, converted to type T.<T> T
val(T fieldValue)
A shortcut ofval(String, Object)
, with name is taken fromname
property of the config.
-
-
-
Field Detail
-
FORM_VALUESS_ATTRIBUTE
@Deprecated public static final java.lang.String FORM_VALUESS_ATTRIBUTE
Deprecated.The Servlet attribute key to store the ValueMap of the form values.- See Also:
- Constant Field Values
-
CONTENTPATH_ATTRIBUTE
@Deprecated public static final java.lang.String CONTENTPATH_ATTRIBUTE
Deprecated.The Servlet attribute key to store the path to the resource holding the form values.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Value
public Value(@Nonnull SlingHttpServletRequest request, @Nonnull Config config)
Instantiates a new Value.- Parameters:
request
- The request storing the FormDataconfig
- The config of the form field component
-
-
Method Detail
-
get
@Nonnull public java.lang.String get(@CheckForNull java.lang.String name)
A shortcut toget(String, Object)
, with empty string as default value.- Parameters:
name
- The name of the field- Returns:
- The value converted to type T, or the value of
value
property, or the given default value, depending on the conditions described atget(String, Object)
.
-
get
@Nonnull public <T> T get(@CheckForNull java.lang.String name, @Nonnull T defaultValue)
Returns the value for the given name, converted to type T.In the
FormData.NameNotFoundMode.CHECK_FRESHNESS
mode, if the given name is not found and the FormData is fresh, then the given fieldValue is returned. Otherwise, the given defaultValue is returned.In the
FormData.NameNotFoundMode.IGNORE_FRESHNESS
mode, if the given name is not found, then the given fieldValue is returned.If the FormData is
null
orignoreData
property of the config istrue
, this method returnsvalue
property of the config.- Type Parameters:
T
- The type of the value- Parameters:
name
- The name of the fielddefaultValue
- The default value- Returns:
- The value converted to type T, or the value of
value
property, or the given default value, depending on the conditions described above.
-
get
@CheckForNull public <T> T get(@CheckForNull java.lang.String name, @Nonnull java.lang.Class<T> type)
Returns the value for the given name, converted to type T.In the
FormData.NameNotFoundMode.CHECK_FRESHNESS
mode, if the given name is not found and the FormData is fresh, then the given fieldValue is returned. Otherwise,null
is returned.In the
FormData.NameNotFoundMode.IGNORE_FRESHNESS
mode, if the given name is not found, then the given fieldValue is returned.If the FormData is
null
orignoreData
property of the config istrue
, this method returnsvalue
property of the config.- Type Parameters:
T
- The type of the value- Parameters:
name
- The name of the fieldtype
- The class of the type- Returns:
- The value converted to type T, or the value of
value
property, ornull
, depending on the conditions described above.
-
val
@CheckForNull public <T> T val(@Nonnull T fieldValue)
A shortcut ofval(String, Object)
, with name is taken fromname
property of the config.- Type Parameters:
T
- The type of the value- Parameters:
fieldValue
- The value of the field- Returns:
- The value converted to type T, or the given fieldValue, or
null
, depending on the conditions described atval(String, Object)
.
-
val
@CheckForNull public <T> T val(@CheckForNull java.lang.String name, @Nonnull T fieldValue)
Returns the value for the given name, converted to type T.In the
FormData.NameNotFoundMode.CHECK_FRESHNESS
mode, if the given name is not found and the FormData is fresh, then the given fieldValue is returned. Otherwise,null
is returned.In the
FormData.NameNotFoundMode.IGNORE_FRESHNESS
mode, if the given name is not found, then the given fieldValue is returned.If the FormData is
null
orignoreData
property of the config istrue
, this method returns the given fieldValue.The key difference compared to
get(String, Object)
is that this method will return the given fieldValue instead of value fromvalue
property of the config.- Type Parameters:
T
- The type of the value- Parameters:
name
- The name of the fieldfieldValue
- The value of the field- Returns:
- The value converted to type T, or the given fieldValue, or
null
, depending on the conditions described above.
-
isSelected
public boolean isSelected(@CheckForNull java.lang.String value, boolean isFieldOptionSelected)
A shortcut ofisSelected(String, String, boolean)
, with name is taken fromname
property of the config.- Parameters:
value
- The value of the field option to compare againstisFieldOptionSelected
-true
if the field option is selected;false
otherwise.- Returns:
- Whether the given value is selected or not, or the given
isFieldOptionSelected, depending on the conditions described at
isSelected(String, String, boolean)
.
-
isSelected
public boolean isSelected(@CheckForNull java.lang.String value, boolean isFieldOptionSelected, boolean forceIgnoreFreshness)
A shortcut ofisSelected(String, String, boolean, boolean)
, with name is taken fromname
property of the config.- Parameters:
value
- The value of the field option to compare againstisFieldOptionSelected
-true
if the field option is selected;false
otherwise.forceIgnoreFreshness
-true
to force to beFormData.NameNotFoundMode.IGNORE_FRESHNESS
;false
otherwise.- Returns:
- Whether the given value is selected or not, or the given
isFieldOptionSelected, depending on the conditions described at
isSelected(String, String, boolean)
.
-
isSelected
public boolean isSelected(@CheckForNull java.lang.String name, @CheckForNull java.lang.String value, boolean isFieldOptionSelected)
- Parameters:
name
- The name of the fieldvalue
- The value of the field option to compare againstisFieldOptionSelected
-true
if the field option is selected;false
otherwise.- Returns:
- Whether the given value is selected or not, or the given isFieldOptionSelected, depending on the conditions described above.
-
isSelected
public boolean isSelected(@CheckForNull java.lang.String name, @CheckForNull java.lang.String value, boolean isFieldOptionSelected, boolean forceIgnoreFreshness)
Returnstrue
if the given value of the field option is selected;false
otherwise.In the
FormData.NameNotFoundMode.CHECK_FRESHNESS
mode, if the given name is not found and the FormData is fresh, then the given isFieldOptionSelected is returned,false
otherwise.In the
FormData.NameNotFoundMode.IGNORE_FRESHNESS
mode, if the given name is not found, then the given isFieldOptionSelected is returned.If the FormData is
null
orignoreData
property of the config istrue
, the given isFieldOptionSelected is returned.- Parameters:
name
- The name of the fieldvalue
- The value of the field option to compare againstisFieldOptionSelected
-true
if the field option is selected;false
otherwise.forceIgnoreFreshness
-true
to force to beFormData.NameNotFoundMode.IGNORE_FRESHNESS
;false
otherwise.- Returns:
- Whether the given value is selected or not, or the given isFieldOptionSelected, depending on the conditions described above.
-
getContentValue
@Nonnull public java.lang.String getContentValue(@CheckForNull java.lang.String name)
A shortcut togetContentValue(String, Object)
, with empty string as default value.- Parameters:
name
- The name of the field- Returns:
- The value converted to String, or an empty String if non existing or can't be converted.
-
getContentValue
@Nonnull public <T> T getContentValue(@CheckForNull java.lang.String name, @Nonnull T defaultValue)
Returns value from the given name, converted to the type of given default value.- Type Parameters:
T
- The type of the value- Parameters:
name
- The name of the fielddefaultValue
- The default value- Returns:
- The value converted to type T, or the default value if non existing or can't be converted.
-
getContentValue
@CheckForNull public <T> T getContentValue(@CheckForNull java.lang.String name, @Nonnull java.lang.Class<T> type)
Returns value from the given name, converted to the given type.- Type Parameters:
T
- The type of the value- Parameters:
name
- The name of the value to returntype
- The return type- Returns:
- The named value converted to type T, or
null
if non existing or can't be converted.
-
-