Skip to content

Commit

Permalink
FORGE-2493: UISelectOne<String> should not take candy from strangers
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Sep 30, 2015
1 parent 44f3acd commit fcbf19f
Showing 1 changed file with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ private static void setManyInputValue(final ConverterFactory converterFactory,
}

/**
* Returns the converted value that matches the input. Throws {@link IllegalArgumentException} if input is a
* {@link SelectComponent} and the value cannot be converted
* Returns the converted value that matches the input.
*/
public static Object convertToUIInputValue(final ConverterFactory converterFactory,
final InputComponent<?, ?> input, final Object value)
Expand Down Expand Up @@ -245,7 +244,38 @@ public static Object convertToUIInputValue(final ConverterFactory converterFacto
}
else
{
result = value;
if (input instanceof SelectComponent)
{
SelectComponent<?, Object> selectComponent = (SelectComponent<?, Object>) input;
Iterable<Object> valueChoices = selectComponent.getValueChoices();
final Converter<Object, ?> selectConverter;
if (String.class.isAssignableFrom(sourceType))
{
selectConverter = getItemLabelConverter(converterFactory, selectComponent);
}
else
{
selectConverter = converterFactory.getConverter(targetType, sourceType);
}
Object chosenObj = null;
if (valueChoices != null)
{
for (Object valueChoice : valueChoices)
{
Object convertedObj = selectConverter.convert(valueChoice);
if (convertedObj.equals(value))
{
chosenObj = valueChoice;
break;
}
}
}
result = chosenObj;
}
else
{
result = value;
}
}
}
return result;
Expand Down

0 comments on commit fcbf19f

Please sign in to comment.