Class FormData
- java.lang.Object
-
- com.adobe.granite.ui.components.FormData
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFormData.NameNotFoundModeThe mode on how to handle the scenario when the FormData doesn't have an entry of a certain name.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static FormDatafrom(SlingHttpServletRequest request)Returns the current FormData.<T> Tget(String name, T fieldValue, Class<T> type)Returns the value for the given name, converted to type T.<T> Tget(String name, T fieldValue, T defaultValue)Returns the value for the given name, converted to type T.FormData.NameNotFoundModegetMode()Returns the mode of the FormData.ValueMapgetValueMap()Returns the values.booleanisSelected(String name, String value, boolean isFieldOptionSelected)An overload ofisSelected(String, String, boolean, boolean)whereforceIgnoreFreshnessparameter isfalse.booleanisSelected(String name, String value, boolean isFieldOptionSelected, boolean forceIgnoreFreshness)Returnstrueif the given value of the field option is selected;falseotherwise.static FormDatapop(SlingHttpServletRequest request)Pops the current FormData.static FormDatapush(SlingHttpServletRequest request, ValueMap values, FormData.NameNotFoundMode nameNotFoundMode)Creates a new FormData representing the given values to the request scope.
-
-
-
Method Detail
-
push
@Nonnull public static FormData push(@Nonnull SlingHttpServletRequest request, @Nonnull ValueMap values, @Nonnull FormData.NameNotFoundMode nameNotFoundMode)
Creates a new FormData representing the given values to the request scope. FormData supports nesting. By calling this method, a new FormData is created and becomes the current context.- Parameters:
request- The request to store the valuesvalues- The values of the FormDatanameNotFoundMode- The mode when the FormData doesn't have an entry of a certain name- Returns:
- The new instance of FormData
-
pop
@Nonnull public static FormData pop(@Nonnull SlingHttpServletRequest request) throws IllegalStateException
Pops the current FormData.- Parameters:
request- The request storing the values- Returns:
- The current FormData
- Throws:
IllegalStateException- When this method is called beforepush(SlingHttpServletRequest, ValueMap, NameNotFoundMode)
-
from
@CheckForNull public static FormData from(@Nonnull SlingHttpServletRequest request)
Returns the current FormData.- Parameters:
request- The request storing the values- Returns:
- The current FormData or
nullif there is none
-
getMode
@Nonnull public FormData.NameNotFoundMode getMode()
Returns the mode of the FormData.- Returns:
- The mode
-
get
@CheckForNull public <T> T get(@Nonnull String name, @CheckForNull T fieldValue, @Nonnull Class<T> type)
Returns the value for the given name, converted to type T.In the
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
NameNotFoundMode#IGNORE_FRESHNESSmode, if the given name is not found, then the given fieldValue is returned.- Type Parameters:
T- The type of the value- Parameters:
name- The name of the fieldfieldValue- The value of the fieldtype- The class of the type- Returns:
- The value converted to type T, or the given fieldValue, or
null, depending on the conditions described above.
-
get
@Nonnull public <T> T get(@Nonnull String name, @Nonnull T fieldValue, @Nonnull T defaultValue)
Returns the value for the given name, converted to type T.In the
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
NameNotFoundMode#IGNORE_FRESHNESSmode, if the given name is not found, then the given fieldValue is returned.- Type Parameters:
T- The type of the value- Parameters:
name- The name of the fieldfieldValue- The value of the fielddefaultValue- The default value- Returns:
- The value converted to type T, or the given fieldValue, or the given default value, depending on the conditions described above.
-
isSelected
public boolean isSelected(@Nonnull String name, @CheckForNull String value, boolean isFieldOptionSelected)
An overload ofisSelected(String, String, boolean, boolean)whereforceIgnoreFreshnessparameter isfalse.- 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(@Nonnull String name, @CheckForNull String value, boolean isFieldOptionSelected, boolean forceIgnoreFreshness)
Returnstrueif the given value of the field option is selected;falseotherwise.In the
NameNotFoundMode#CHECK_FRESHNESSmode, if the given name is not found and the FormData is fresh, then the given isFieldOptionSelected is returned,falseotherwise.In the
NameNotFoundMode#IGNORE_FRESHNESSmode, if the given name is not found, then 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.
-
-