-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
b:selectOneMenu null itemValue #939
Comments
I am not sure this is the correct way to do. Selectonemenu does not support null value. If it is empty then the bean has to convert as null. |
It was a deliberate choice to use the label if the value is missing, but probably it wasn't a wise choice. I've removed it because we've never documented the feature. Still, it's a breaking change. Passing null values to the bean is difficult. During my test the null value has always been replaced by an empty string. To avoid that, you probably have to set the parameter @chongma Can you review and test my changes, please? |
Null is not an value. It means empty. JSF treats everything as string and the converters to the rest of the work to convert it to objects. There is no "null" object. This will fail always. |
I have been passing nulls for a long time with (usually) no problem. But looking at this answer by @BalusC it seems that @dguna is correct and that the preferred method is to pass an empty string. Not sure why null always worked for me before https://stackoverflow.com/questions/17052503/using-a-please-select-fselectitem-with-null-empty-value-inside-a-pselectonem?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa |
@dguna You are right... mostly. Have a look at Bauke's well-researched article. |
I'll close this ticket. If anyone of your finds a bug in my bugfix, don't hesitate to re-open the ticket. |
Don"t close it yet. You have to give an option as f:selectitems noSelectionOption="true", it means empty string and if required=true, it should not be submitted. JSF automatically converts empty as null, if I am correct. Please look at the Primefaces selectonemenu. |
There are several references to private SelectItemAndComponent determineSelectedItem(FacesContext context, SelectOneMenu menu, List<SelectItemAndComponent> items, Converter converter) {
Object submittedValue = menu.getSubmittedValue();
Object selectedOption;
if (submittedValue != null) {
selectedOption = submittedValue;
} else {
selectedOption = menu.getValue();
}
for (int index = 0; index < items.size(); index++) {
SelectItemAndComponent option = items.get(index);
if (option.getSelectItem().isNoSelectionOption()) continue;
Object itemValue = option.getSelectItem().getValue();
String itemValueAsString = getOptionAsString(context, menu, itemValue, converter);
Object optionValue;
if (submittedValue != null) {
optionValue = itemValueAsString;
} else {
optionValue = itemValue;
}
if (itemValue != null) {
if (isSelected(context, menu, selectedOption, optionValue, converter)) {
return option;
}
}
}
return null;
}
|
consider the following
h:selectOneMenu
code snippet:when
Not selected
is selected thenmyBean.value
equalsnull
whereas with
b:selectOneMenu
whenNot selected
is selected thenmyBean.value
equalsNot selected
The text was updated successfully, but these errors were encountered: