{
arrayComponentType = valueType.getComponentType();
}
}
Converter converter = component.getConverter();
if (converter == null)
{
if (valueType == null)
{
// No converter, and no idea of expected type
// --> return the submitted String array
return submittedValue;
}
if (List.class.isAssignableFrom(valueType))
{
// expected type is a List
// --> according to javadoc of UISelectMany we assume that the element type
// is java.lang.String, and copy the String array to a new List
int len = submittedValue.length;
List lst = new ArrayList(len);
for (int i = 0; i < len; i++)
{
lst.add(submittedValue[i]);
}
return lst;
}
if (arrayComponentType == null)
{
throw new IllegalArgumentException("ValueBinding for UISelectMany must be of type List or Array");
}
if (Object.class.equals(arrayComponentType)) return submittedValue; //No conversion for Object class
converter = facesContext.getApplication().createConverter(arrayComponentType);
if (converter == null)
{
return submittedValue;
}
}
// Now, we have a converter...
// We determine the type of the component array after converting one of it's elements
if (expression != null)
{
valueType = expression.getType(facesContext.getELContext());
if (valueType != null && valueType.isArray())
{
if (submittedValue.length > 0)
{
arrayComponentType = converter.getAsObject(facesContext, component, submittedValue[0]).getClass();
}
}
}
if (valueType == null)
{
// ...but have no idea of expected type
// --> so let's convert it to an Object array
int len = submittedValue.length;
Object [] convertedValues = (Object []) Array.newInstance(
arrayComponentType==null?Object.class:arrayComponentType,len);
for (int i = 0; i < len; i++)
{
convertedValues[i]
= converter.getAsObject(facesContext, component, submittedValue[i]);
}
return convertedValues;
}
if (List.class.isAssignableFrom(valueType))
{
// Curious case: According to specs we should assume, that the element type
// of this List is java.lang.String. But there is a Converter set for this
// component. Because the user must know what he is doing, we will convert the values.
int len = submittedValue.length;
List lst = new ArrayList(len);
for (int i = 0; i < len; i++)
{
lst.add(converter.getAsObject(facesContext, component, submittedValue[i]));
}
return lst;
}
if (arrayComponentType == null)
{
throw new IllegalArgumentException("ValueBinding for UISelectMany must be of type List or Array");
}
if (arrayComponentType.isPrimitive())
{
//primitive array
int len = submittedValue.length;
Object convertedValues = Array.newInstance(arrayComponentType, len);
for (int i = 0; i < len; i++)
{
Array.set(convertedValues, i,
converter.getAsObject(facesContext, component, submittedValue[i]));
}
return convertedValues;
}
//Object array
int len = submittedValue.length;
ArrayList convertedValues = new ArrayList(len);
for (int i = 0; i < len; i++)
{
convertedValues.add(i, converter.getAsObject(facesContext, component, submittedValue[i]));
}
return convertedValues.toArray((Object[]) Array.newInstance(arrayComponentType, len));
}