Class Value

    • Constructor Detail

      • Value

        public Value​(@Nonnull
                     SlingHttpServletRequest request,
                     @Nonnull
                     Config config)
        Instantiates a new Value.
        Parameters:
        request - The request storing the FormData
        config - The config of the form field component
    • Method Detail

      • get

        @Nonnull
        public java.lang.String get​(@CheckForNull
                                    java.lang.String name)
        A shortcut to get(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 at get(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 or ignoreData property of the config is true, this method returns value property of the config.

        Type Parameters:
        T - The type of the value
        Parameters:
        name - The name of the field
        defaultValue - 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 or ignoreData property of the config is true, this method returns value property of the config.

        Type Parameters:
        T - The type of the value
        Parameters:
        name - The name of the field
        type - The class of the type
        Returns:
        The value converted to type T, or the value of value property, or null, depending on the conditions described above.
      • val

        @CheckForNull
        public <T> T val​(@Nonnull
                         T fieldValue)
        A shortcut of val(String, Object), with name is taken from name 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 at val(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 or ignoreData property of the config is true, 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 from value property of the config.

        Type Parameters:
        T - The type of the value
        Parameters:
        name - The name of the field
        fieldValue - 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 of isSelected(String, String, boolean), with name is taken from name property of the config.
        Parameters:
        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 at isSelected(String, String, boolean).
      • isSelected

        public boolean isSelected​(@CheckForNull
                                  java.lang.String value,
                                  boolean isFieldOptionSelected,
                                  boolean forceIgnoreFreshness)
        A shortcut of isSelected(String, String, boolean, boolean), with name is taken from name property of the config.
        Parameters:
        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 at isSelected(String, String, boolean).
      • isSelected

        public boolean isSelected​(@CheckForNull
                                  java.lang.String name,
                                  @CheckForNull
                                  java.lang.String value,
                                  boolean isFieldOptionSelected)
        An overload of isSelected(String, String, boolean, boolean) where forceIgnoreFreshness 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​(@CheckForNull
                                  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 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 or ignoreData property of the config is true, 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.
      • getContentValue

        @Nonnull
        public java.lang.String getContentValue​(@CheckForNull
                                                java.lang.String name)
        A shortcut to getContentValue(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 field
        defaultValue - 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 return
        type - The return type
        Returns:
        The named value converted to type T, or null if non existing or can't be converted.