public void submitValue(String expression, Object value) throws UnsupportedOperationException
{
FacesContext facesContext = getFacesContext();
ELContext elContext = facesContext.getELContext();
ValueExpression valueExpression = getValueExpression(facesContext, expression);
Class<?> referencedType = valueExpression.getType(elContext);
// the value that will be injected
Object toInject = null;
// the expression is referencing an array
if (referencedType.isArray()) {
// ensure the value that will be injected is an array
if (value != null && !value.getClass().isArray()) {
toInject = new Object[] { value };
}
else {
toInject = value;
}
}
// expression is not referencing an array
else {
// if value to inject is an array, just use the first element
if (value != null && value.getClass().isArray()) {
Object[] valueAsArray = (Object[]) value;
if (valueAsArray.length > 0) {
toInject = valueAsArray[0];
}
else {
toInject = null;
}
}
// simple case: neither the expression is referencing an array nor the value is one
else {
toInject = value;
}
}
// set the value
Object coercedValue = facesContext.getApplication().getExpressionFactory().coerceToType(toInject, referencedType);
valueExpression.setValue(elContext, coercedValue);
}