Class FormData


  • public class FormData
    extends java.lang.Object
    FormData represents the values of the form.

    The values are represented as a ValueMap. The FormData is set at request scope, where usually it is set by the form component and read by the field components.

    • 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 values
        values - The values of the FormData
        nameNotFoundMode - The mode when the FormData doesn't have an entry of a certain name
        Returns:
        The new instance of FormData
      • 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 null if there is none
      • getValueMap

        @Nonnull
        public ValueMap getValueMap()
        Returns the values.
        Returns:
        The values
      • get

        @CheckForNull
        public <T> T get​(@Nonnull
                         java.lang.String name,
                         @CheckForNull
                         T fieldValue,
                         @Nonnull
                         java.lang.Class<T> type)
        Returns the value for the given name, converted to type T.

        In the 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 NameNotFoundMode#IGNORE_FRESHNESS mode, 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 field
        fieldValue - The value of the field
        type - 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
                         java.lang.String name,
                         @Nonnull
                         T fieldValue,
                         @Nonnull
                         T defaultValue)
        Returns the value for the given name, converted to type T.

        In the 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 NameNotFoundMode#IGNORE_FRESHNESS mode, 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 field
        fieldValue - The value of the field
        defaultValue - 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
                                  java.lang.String name,
                                  @CheckForNull
                                  java.lang.String value,
                                  boolean isFieldOptionSelected)
        An overload of isSelected(String, String, boolean, boolean) where forceIgnoreFreshness parameter is false.
        Parameters:
        name - The name of the field
        value - The value of the field option to compare against
        isFieldOptionSelected - 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​(@Nonnull
                                  java.lang.String name,
                                  @CheckForNull
                                  java.lang.String value,
                                  boolean isFieldOptionSelected,
                                  boolean forceIgnoreFreshness)
        Returns true if the given value of the field option is selected; false otherwise.

        In the 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 NameNotFoundMode#IGNORE_FRESHNESS mode, if the given name is not found, then the given isFieldOptionSelected is returned.

        Parameters:
        name - The name of the field
        value - The value of the field option to compare against
        isFieldOptionSelected - true if the field option is selected; false otherwise.
        forceIgnoreFreshness - true to force to be FormData.NameNotFoundMode.IGNORE_FRESHNESS; false otherwise.
        Returns:
        Whether the given value is selected or not, or the given isFieldOptionSelected, depending on the conditions described above.