Class SplibThymeleafOptionUtil

java.lang.Object
jp.ecuacion.splib.web.util.SplibThymeleafOptionUtil

@Component("optUtil") public class SplibThymeleafOptionUtil extends Object
Analyzes options specified with html components.

It's called from thymeleaf.
Options are in the format of csv and able to receive multiple optional attributes. It's written like 'readonly,required'.
It also receives key value parameter like 'readonly,id=deptName,required'.

  • Constructor Details

    • SplibThymeleafOptionUtil

      public SplibThymeleafOptionUtil()
      Constructs a new instance.
  • Method Details

    • hasKey

      public boolean hasKey(String options, String key)
      Returns if specified key exists in options.
    • getValue

      public String getValue(String options, String key)
      Returns value obtained from the key.
      Parameters:
      options - options
      key - key
      Returns:
      value
    • getValueOrElse

      public String getValueOrElse(String options, String key, String defaultValue)
      Returns value obtained from the key, or defaultValue when the key does not exist in the properties file.
      Parameters:
      options - options
      key - key
      defaultValue - defaultValue
      Returns:
      value
    • getValues

      public String[] getValues(String options, String key)
      Returns values obtained from the key as an array.

      When you want to give multiple options of the same key (like add 2 classes to an element), you are supposed to set 2 key-value pairs, like 'classappend=class1,classapeend=class2'. In this case getValues(options, 'classappend') return {'class1', 'class2'}.

      Parameters:
      options - options
      key - key
      Returns:
      value
    • getValuesInSpaceSeparetedFormat

      public String getValuesInSpaceSeparetedFormat(String options, String key)
      Returns values in space separated format. It's supposed to be used for class attributes.
    • getElementFromPsv

      public String getElementFromPsv(String options, String key, int psvIndex)
      Obtains an element string from designated ordinal number of pipe separated values (psv) format string from designated index of multiple option values.

      For example, option: 'attr' is used for th:attr to add attribute dynamically to the tag.
      'attr' needs to have its key and value, so option format becomes 'attr=key1|value1'.
      (when a single option needs to have multiple different meaning string like key and value, option should be pipe separated format.
      When you want to list multiple strings of same meaning set xxx=yyy multiple times (like 'classappend=mt-3,classappend=mb-3'))

    • getElementFromPsvOrElse

      public String getElementFromPsvOrElse(String options, String key, int psvIndex, String defaultValue)
      Returns getElementFromPsv or else.
    • getElementFromValuesOfPsv

      public String getElementFromValuesOfPsv(String options, String key, int arrayIndex, int psvIndex)
      Obtains an element from an array of psv strings.
    • getElementFromValuesOfPsvOrElse

      public String getElementFromValuesOfPsvOrElse(String options, String key, int arrayIndex, int psvIndex, String defaultValue)
      Obtains an element from an array of psv strings or else.