Uploaded image for project: 'XWiki Commons'
  1. XWiki Commons
  2. XCOMMONS-129

Add a tool or a method to an existing tool so that you can convert an Array to a List in Velocity

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Unresolved
    • Major
    • None
    • 3.5
    • Velocity
    • None
    • velocity array list conversion

    Description

      Even if Velocity claims that all arrays are actually ArrayLists, when an API returns an array that claim is no longer true and you are forced to work with an array in Velocity. This means that, even with all the available standard tools, you can not add elements to that array and you can not even convert it directly to a list without iterating all its elements and adding them to a second (empty) list.

      A clear example is:

      #set ($aString = 'this is a test')
      #set ($array = $aString.split(' '))
      $array[0] - $array[1] - $array[2] - $array[3]
      $array.class
      $array.length
      $array.size()
      

      Outputs:

      this - is - a - test
      class [Ljava.lang.String;
      $array.length
      4
      

      The funny thing is that $array.length does not work, but $array.size() does . I`m guessing that $listtool is used automatically for calls to size() but the array is not converted automatically to List for the call of String.split().

      The conclusion is that we need a tool or to extend an existing tool ($listtool ?) and add a method that converts an array to a list (calling Arrays.asList(array) in the implementation).

      Attachments

        Activity

          People

            Unassigned Unassigned
            enygma Eduard Moraru
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: