Class DesignToStringConverter<TYPE>

  • Type Parameters:
    TYPE - Type of the data being converted.
    All Implemented Interfaces:
    Converter<java.lang.String,​TYPE>, java.io.Serializable

    public class DesignToStringConverter<TYPE>
    extends java.lang.Object
    implements Converter<java.lang.String,​TYPE>
    Utility class for DesignAttributeHandler that deals with converting various types to string.
    Since:
    7.4
    Author:
    Vaadin Ltd
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String NULL_VALUE_REPRESENTATION
      A string that corresponds to how a null value is stored.
    • Constructor Summary

      Constructors 
      Constructor Description
      DesignToStringConverter​(java.lang.Class<? extends TYPE> type)
      Constructs the converter for a given type.
      DesignToStringConverter​(java.lang.Class<? extends TYPE> type, java.lang.String staticMethodName)
      Constructs the converter for a given type, giving the name of the public static method that does the conversion from String.
    • Field Detail

      • NULL_VALUE_REPRESENTATION

        public static final java.lang.String NULL_VALUE_REPRESENTATION
        A string that corresponds to how a null value is stored.
        See Also:
        Constant Field Values
    • Constructor Detail

      • DesignToStringConverter

        public DesignToStringConverter​(java.lang.Class<? extends TYPE> type)
        Constructs the converter for a given type. Implicitly requires that a static method valueOf(String) is present in the type to do the conversion.
        Parameters:
        type - Type of values to convert.
      • DesignToStringConverter

        public DesignToStringConverter​(java.lang.Class<? extends TYPE> type,
                                       java.lang.String staticMethodName)
        Constructs the converter for a given type, giving the name of the public static method that does the conversion from String.
        Parameters:
        type - Type to convert.
        staticMethodName - Method to call when converting from String to this type. This must be public and static method that returns an object of passed type.
    • Method Detail

      • convertToModel

        public Result<TYPE> convertToModel​(java.lang.String value,
                                           ValueContext context)
        Description copied from interface: Converter
        Converts the given value from model type to presentation type.

        A converter can optionally use locale to do the conversion.

        Specified by:
        convertToModel in interface Converter<java.lang.String,​TYPE>
        Parameters:
        value - The value to convert. Can be null
        context - The value context for the conversion.
        Returns:
        The converted value compatible with the source type
      • convertToPresentation

        public java.lang.String convertToPresentation​(TYPE value,
                                                      ValueContext context)
        Description copied from interface: Converter
        Converts the given value from presentation type to model type.

        A converter can optionally use locale to do the conversion.

        Specified by:
        convertToPresentation in interface Converter<java.lang.String,​TYPE>
        Parameters:
        value - The value to convert. Can be null
        context - The value context for the conversion.
        Returns:
        The converted value compatible with the source type