Skip to content

Commit

Permalink
FORGE-2577: Fix InputComponents.convertToUIInputValue comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jan 13, 2016
1 parent aab2a80 commit 20d8b0f
Showing 1 changed file with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.jboss.forge.addon.convert.CompositeConverter;
import org.jboss.forge.addon.convert.Converter;
Expand All @@ -23,6 +24,7 @@
import org.jboss.forge.addon.ui.input.SelectComponent;
import org.jboss.forge.addon.ui.input.SingleValued;
import org.jboss.forge.addon.ui.input.UICompleter;
import org.jboss.forge.furnace.util.Sets;
import org.jboss.forge.furnace.util.Strings;

/**
Expand Down Expand Up @@ -213,6 +215,7 @@ public static Object convertToUIInputValue(final ConverterFactory converterFacto
}
else
{

Converter<String, Object> valueConverter = (Converter<String, Object>) input.getValueConverter();
if (valueConverter != null)
{
Expand All @@ -237,6 +240,7 @@ public static Object convertToUIInputValue(final ConverterFactory converterFacto
}
else
{

Converter<String, Object> valueConverter = (Converter<String, Object>) input.getValueConverter();
if (valueConverter != null && value instanceof String)
{
Expand All @@ -249,23 +253,33 @@ public static Object convertToUIInputValue(final ConverterFactory converterFacto
if (input instanceof SelectComponent && !Boolean.getBoolean("org.jboss.forge.ui.select_one_lenient_value"))
{
SelectComponent<?, Object> selectComponent = (SelectComponent<?, Object>) input;
Iterable<Object> valueChoices = selectComponent.getValueChoices();
Converter<Object, String> selectConverter = getItemLabelConverter(converterFactory, selectComponent);
String valueLabel = selectConverter.convert(value);
Object chosenObj = null;
if (valueChoices != null)
Set<Object> valueChoices = Sets.toSet(selectComponent.getValueChoices());
// Check if the value is contained in the valueChoices set
if (valueChoices != null && valueChoices.contains(value))
{
result = value;
}
else
{
for (Object valueChoice : valueChoices)
// equals()/hashCode may not have been implemented. Trying to compare from the String representation
Object chosenObj = null;
if (valueChoices != null)
{
String convertedObj = selectConverter.convert(valueChoice);
if (convertedObj.equals(valueLabel))
Converter<Object, String> selectConverter = getItemLabelConverter(converterFactory,
selectComponent);
String valueLabel = selectConverter.convert(value);
for (Object valueChoice : valueChoices)
{
chosenObj = valueChoice;
break;
String convertedObj = selectConverter.convert(valueChoice);
if (convertedObj.equals(valueLabel))
{
chosenObj = valueChoice;
break;
}
}
}
result = chosenObj;
}
result = chosenObj;
}
else
{
Expand Down

0 comments on commit 20d8b0f

Please sign in to comment.