Class Value
FormData.
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
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionValue(SlingHttpServletRequest request, Config config) Instantiates a new Value. -
Method Summary
Modifier and TypeMethodDescriptionA shortcut toget(String, Object), with empty string as default value.<T> TReturns the value for the given name, converted to type T.<T> TReturns the value for the given name, converted to type T.getContentValue(String name) A shortcut togetContentValue(String, Object), with empty string as default value.<T> TgetContentValue(String name, Class<T> type) Returns value from the given name, converted to the given type.<T> TgetContentValue(String name, T defaultValue) Returns value from the given name, converted to the type of given default value.booleanisSelected(String value, boolean isFieldOptionSelected) A shortcut ofisSelected(String, String, boolean), with name is taken fromnameproperty of the config.booleanisSelected(String value, boolean isFieldOptionSelected, boolean forceIgnoreFreshness) A shortcut ofisSelected(String, String, boolean, boolean), with name is taken fromnameproperty of the config.booleanisSelected(String name, String value, boolean isFieldOptionSelected) booleanisSelected(String name, String value, boolean isFieldOptionSelected, boolean forceIgnoreFreshness) Returnstrueif the given value of the field option is selected;falseotherwise.<T> TReturns 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 Details
-
FORM_VALUESS_ATTRIBUTE
Deprecated.The Servlet attribute key to store the ValueMap of the form values.- See Also:
-
CONTENTPATH_ATTRIBUTE
Deprecated.The Servlet attribute key to store the path to the resource holding the form values.- See Also:
-
-
Constructor Details
-
Value
Instantiates a new Value.- Parameters:
request- The request storing the FormDataconfig- The config of the form field component
-
-
Method Details
-
get
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
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
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
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
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 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 String name, @CheckForNull 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 String name, @CheckForNull 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
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
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
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.
-
FormData.push(SlingHttpServletRequest, ValueMap, NameNotFoundMode)instead