Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

noSelectionOption Attribute [duplicate]

Tags:

jsf

jsf-2

I am new to JSF and I came across the noSelectionOption attribute in JSF 2.0.

I don't understand the purpose of this attribute. As per the description, it's used when the selection is required and the user selects noSelectionOption causing a validation error.

So, if noSelectionOption = true then the user can select noSelectionOption and bypass that list or menu?

Or, if noSelectionOption = true then the user has to select one of the items, and, if he chooses noSelectionOption then the validation error occurs?

Can the user see noSelectionOption as one of the items under the List or menu if it's true?

Please help me to understand the logic behind this.

like image 879
devOpsTools Avatar asked Jan 15 '23 23:01

devOpsTools


1 Answers

A f:selectItem that has noSelectOption set to true represents a "no selection" option, something like this:

-- Select a Colour -- < noSelectOption was intended for this case
Red
Green
Blue
Tomato

This item is rendered in the menu, unless hideNoSelectionOption is set to true in your menu component. In that case, the option is selected when the user interacts with the menu.

Just bear in mind that if an entry is required and this "no selection" option is the one selected, there will be a validation error.

An alternative that requires a little more of coding is to use a f:selectItem with value="#{null}", to represent the case in which an user did not select a value. If you have a converter you'll have to check for this null case and, if you feel like it, introduce some custom validators.

like image 136
Fritz Avatar answered Jan 22 '23 18:01

Fritz