// if we have no local value, try to get the valueBinding.
ValueBinding valueBinding = component.getValueBinding("value");
Converter converter = null;
Object result = null;
// If there is a converter attribute, use it to to ask application
// instance for a converter with this identifer.
if (component instanceof ValueHolder) {
converter = ((ValueHolder) component).getConverter();
}
if (null == converter && null != valueBinding) {
Class converterType = valueBinding.getType(context);
// if converterType is null, assume the modelType is "String".
if (converterType == null || converterType == String.class
|| converterType == Object.class) {
if (log.isDebugEnabled()) {
log.debug("No conversion necessary for " + submittedValue
+ "and converterType " + converterType
+ " while decoding component " + component.getId());
}
return submittedValue;
}
// if getType returns a type for which we support a default
// conversion, acquire an appropriate converter instance.
try {
Application application = context.getApplication();
converter = application.createConverter(converterType);
if (log.isDebugEnabled()) {
log.debug("Created converter " + converter + "of type "
+ converterType + " while decoding component "
+ component.getId());
}
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.debug("Converter could not be instantiated for "
+ converterType + " while " + "decoding component "
+ component.getId());
}
if(submittedValue instanceof Object[]){
if (log.isDebugEnabled()) {
log.debug("Assume we have a String array here.");
}
return submittedValue;
}
else {
return (null);
}
}
} else if (converter == null && valueBinding == null) {
// if there is no valueBinding and converter attribute set,
// assume the modelType as "String" since we have no way of
// figuring out the type. So for the selectOne and
// selectMany, converter has to be set if there is no
// valueBinding attribute set on the component.
if (log.isDebugEnabled()) {
log
.debug("No conversion necessary for "
+ submittedValue
+ " while decoding component "
+ component.getId()
+ "since there is no explicitly registered converter and "
+ "component value is not bound to a model property ");
}
return submittedValue;
}
if (converter != null) {
if(submittedValue instanceof Object[]){
String[] submittedValues = (String[]) submittedValue;
Object[] results = new Object[submittedValues.length];
for(int i=0; i < submittedValues.length;i++){
results[i] = converter.getAsObject(context, component, submittedValues[i]);
}
return results;
}
else {
result = converter.getAsObject(context, component, (String)submittedValue);
}
return result;
} else {
if (log.isDebugEnabled()) {
log.debug("Unexpected Converter exception "