Class Value
- java.lang.Object
-
- com.adobe.granite.ui.components.Value
-
public class Value extends java.lang.ObjectA 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_ATTRIBUTEas the key - Set the request attribute using
CONTENTPATH_ATTRIBUTEas the key
- Set the request attribute using
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCONTENTPATH_ATTRIBUTEDeprecated.static java.lang.StringFORM_VALUESS_ATTRIBUTEDeprecated.
-
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.Stringget(java.lang.String name)A shortcut toget(String, Object), with empty string as default value.<T> Tget(java.lang.String name, java.lang.Class<T> type)Returns the value for the given name, converted to type T.<T> Tget(java.lang.String name, T defaultValue)Returns the value for the given name, converted to type T.java.lang.StringgetContentValue(java.lang.String name)A shortcut togetContentValue(String, Object), with empty string as default value.<T> TgetContentValue(java.lang.String name, java.lang.Class<T> type)Returns value from the given name, converted to the given type.<T> TgetContentValue(java.lang.String name, T defaultValue)Returns value from the given name, converted to the type of given default value.booleanisSelected(java.lang.String value, boolean isFieldOptionSelected)A shortcut ofisSelected(String, String, boolean), with name is taken fromnameproperty of the config.booleanisSelected(java.lang.String value, boolean isFieldOptionSelected, boolean forceIgnoreFreshness)A shortcut ofisSelected(String, String, boolean, boolean), with name is taken fromnameproperty of the config.booleanisSelected(java.lang.String name, java.lang.String value, boolean isFieldOptionSelected)booleanisSelected(java.lang.String name, java.lang.String value, boolean isFieldOptionSelected, boolean forceIgnoreFreshness)Returnstrueif the given value of the field option is selected;falseotherwise.<T> Tval(java.lang.String name, T fieldValue)Returns the value for the given name, converted to type T.<T> Tval(T fieldValue)A shortcut ofval(String, Object), with name is taken fromnameproperty 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
valueproperty, 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_FRESHNESSmode, 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_FRESHNESSmode, if the given name is not found, then the given fieldValue is returned.If the FormData is
nullorignoreDataproperty of the config istrue, this method returnsvalueproperty 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
valueproperty, 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_FRESHNESSmode, if the given name is not found and the FormData is fresh, then the given fieldValue is returned. Otherwise,nullis returned.In the
FormData.NameNotFoundMode.IGNORE_FRESHNESSmode, if the given name is not found, then the given fieldValue is returned.If the FormData is
nullorignoreDataproperty of the config istrue, this method returnsvalueproperty 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
valueproperty, 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 fromnameproperty 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_FRESHNESSmode, if the given name is not found and the FormData is fresh, then the given fieldValue is returned. Otherwise,nullis returned.In the
FormData.NameNotFoundMode.IGNORE_FRESHNESSmode, if the given name is not found, then the given fieldValue is returned.If the FormData is
nullorignoreDataproperty 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 fromvalueproperty 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 fromnameproperty of the config.- Parameters:
value- The value of the field option to compare againstisFieldOptionSelected-trueif the field option is selected;falseotherwise.- 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 fromnameproperty of the config.- Parameters:
value- The value of the field option to compare againstisFieldOptionSelected-trueif the field option is selected;falseotherwise.forceIgnoreFreshness-trueto force to beFormData.NameNotFoundMode.IGNORE_FRESHNESS;falseotherwise.- 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-trueif the field option is selected;falseotherwise.- 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)Returnstrueif the given value of the field option is selected;falseotherwise.In the
FormData.NameNotFoundMode.CHECK_FRESHNESSmode, if the given name is not found and the FormData is fresh, then the given isFieldOptionSelected is returned,falseotherwise.In the
FormData.NameNotFoundMode.IGNORE_FRESHNESSmode, if the given name is not found, then the given isFieldOptionSelected is returned.If the FormData is
nullorignoreDataproperty 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-trueif the field option is selected;falseotherwise.forceIgnoreFreshness-trueto force to beFormData.NameNotFoundMode.IGNORE_FRESHNESS;falseotherwise.- 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
nullif non existing or can't be converted.
-
-