示例#1
0
  // Converts the specified object to a List<String>
  private static List<String> toList(
      String propertyName, ValueExpression expression, Object value) {

    if (value instanceof String) {

      String strValue = (String) value;

      // If the value contains no spaces, we can optimize.
      // This is worthwhile, since the execute/render lists
      // will often only contain a single value.
      if (strValue.indexOf(' ') == -1) {
        return toSingletonList(propertyName, strValue);
      }

      // We're stuck splitting up the string.
      String[] values = SPLIT_PATTERN.split(strValue);
      if ((values == null) || (values.length == 0)) {
        return null;
      }

      // Note that we could create a Set out of the values if
      // we care about removing duplicates.  However, the
      // presence of duplicates does not real harm.  They will
      // be consolidated during the partial view traversal.  So,
      // just create an list - garbage in, garbage out.
      return Collections.unmodifiableList(Arrays.asList(values));
    }

    // RELEASE_PENDING i18n ;
    throw new FacesException(
        expression.toString()
            + " : '"
            + propertyName
            + "' attribute value must be either a String or a Collection");
  }