Uploaded image for project: 'MyFaces Core'
  1. MyFaces Core
  2. MYFACES-425

findUISelectManyConverter should look for converter when valueType is List

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.1.0
    • 1.1.0
    • None
    • None

    Description

      Currently the RendererUtils.findUISelectManyConverter() method assumes that, when the valueType is a List, the List must contain Strings, and therefore no Converter is needed. If the valueType is an array, then this method attempts to see if there is a Converter for the arrayComponentType (the type of objects that the array holds). A comment says that the API Doc of UISelectMany assumes that the List holds Strings, but we have an opportunity here to improve on that.

      The patch I'm submitting allows the binding of a UISelectMany component to a List of objects other than Strings. The behavior ends up being the same as if we were binding to an array of some component whose type is not a String (finding a Converter in this case is already handled by the RendererUtils.findUISelectManyConverter() method.

      The code that I propose adding is listed here and a patch file will be attached:

      if (List.class.isAssignableFrom(valueType))
      {
      //According to API Doc of UISelectMany the assumed entry type for a List is String
      //--> no converter needed

      // However, if the List contains something other than Strings, we can attempt
      // to find a suitable converter. In JDK 1.4, we can try to find out what the List
      // contains by looking at the SelectItem value of the first item. With generics in
      // JDK 1.5, it would be much easier to determine the type.
      List selectItems = RendererUtils.internalGetSelectItemList(component);
      if (selectItems != null && selectItems.size() > 0) {
      SelectItem selectItem = (SelectItem) selectItems.get(0);
      Class listComponentType = selectItem.getValue().getClass();
      if (!(String.class.equals(listComponentType))) {
      try

      { return facesContext.getApplication().createConverter(listComponentType); }

      catch (FacesException e)

      { log.error("No Converter for type " + listComponentType.getName() + " found", e); return null; }

      }
      }
      }

      Attachments

        1. RendererUtils.patch.txt
          1 kB
          Ken Weiner

        Activity

          People

            mmarinschek Martin Marinschek
            kweiner Ken Weiner
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: