Skip to content

Commit

Permalink
#939 don't use the item label as value because "null" might be an int…
Browse files Browse the repository at this point in the history
…entional value
  • Loading branch information
stephanrauh committed May 31, 2018
1 parent cd72f95 commit f15934f
Showing 1 changed file with 22 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,34 @@ public void decode(FacesContext context, UIComponent component) {
if (currentOption instanceof SelectItem) {
if (!((SelectItem) currentOption).isDisabled()) {
currentOptionValue = ((SelectItem) currentOption).getValue();
if (null == currentOptionValue) // use the label as
// fall-back
currentOptionValue = ((SelectItem) currentOption).getLabel();
}
}
if (currentOptionValue instanceof String) {
currentOptionValueAsString = (String) currentOptionValue;
} else if (null != converter) {
currentOptionValueAsString = converter.getAsString(context, component, currentOptionValue);
} else
} else if (currentOptionValue != null) {
currentOptionValueAsString = String.valueOf(index);
} else {
currentOptionValueAsString = ""; // null values are submitted as empty strings
}
if (submittedOptionValue.equals(currentOptionValueAsString)) {
menu.setSubmittedValue(null != converter ? currentOptionValueAsString : currentOptionValue);
Object submittedValue = null;
if (currentOptionValue == null) {
submittedValue = null;
} else {
submittedValue = null != converter ? currentOptionValueAsString : currentOptionValue;
}
menu.setSubmittedValue(submittedValue);
menu.setValid(true);
menu.validateValue(context, currentOptionValue);

menu.validateValue(context, submittedValue);
new AJAXRenderer().decode(context, component, clientId);
if (menu.isValid()) {
if (currentOptionValue == null) {
menu.setLocalValueSet(true);
}
}
return;
}
}
Expand Down Expand Up @@ -456,32 +468,8 @@ private void renderOption(FacesContext context, SelectOneMenu menu, ResponseWrit
final String description, final Object itemValue, boolean isDisabledOption, boolean isEscape,
UIComponent itemComponent, boolean isSelected) throws IOException {

Object submittedValue = menu.getSubmittedValue();
Object selectedOption;
Object optionValue;
Converter converter = menu.getConverter();
String itemValueAsString = getOptionAsString(context, menu, itemValue, converter);
if (submittedValue != null) {
selectedOption = submittedValue;
optionValue = itemValueAsString;
} else {
selectedOption = menu.getValue();
optionValue = itemValue;
}

/*boolean isSelected = false;
if (itemValue != null) {
if (isSelected(context, menu, selectedOption, optionValue, converter)) {
isSelected = true;
}
} else if (itemLabel.equals(selectedOption)) {
isSelected = true;
}*/
// if (menu.isDisabled() || menu.isReadonly()) {
// if (!isSelected) {
// return; // don't render options that can't be selected
// }
// }

boolean isItemLabelBlank = itemLabel == null || itemLabel.trim().isEmpty();
itemLabel = isItemLabelBlank ? itemValueAsString : itemLabel;
Expand All @@ -500,10 +488,13 @@ private void renderOption(FacesContext context, SelectOneMenu menu, ResponseWrit
else if (itemValue instanceof String) {
value = (String) itemValue;
} else {
value = String.valueOf(index);
value = String.valueOf(index); // this is used for objects
}
rw.writeAttribute("value", value, "value");
}
else {
rw.writeAttribute("value", "", "value");
}
if (isSelected) {
rw.writeAttribute("selected", "true", "selected");
}
Expand Down

0 comments on commit f15934f

Please sign in to comment.