I'm facing the famous issue of the value error on Dynamic populated Select Items on JSF, the issue is that JSF requires the model to have the selected value on the UI level while this is not valid since the values are not populated on the constructor (fixed) value on the backbean level, so is there a known fix (walk-around) for this behavior.
If your environment is fairly up-to-date, you can do a "@PostConstruct" method to build the resource after construction has completed.
Failing that, leave the resource NULL initially, then in your "get" method, check for null and call a method to initialize it if it is null.
An IDE is no substitute for an Intelligent Developer.
Joined: Apr 10, 2006
Thanks for your reply, but im not sure you got my question right.
The case is that a select items is being populated using ajax , and that list is populated through the "get" method, but when the user selects a value from that list; JSF requires you to have that selected value on the back model, which may does not conatin it.
OK, let me try again. This time I'm understanding you to mean that you haven't yet set the value of the selectOneMenu and it's still null. And you are asking what the consequences are with the selection list?
The answer is that the control should display with the first element in the selection list selected, but the backing value will remain null until the form is actually posted. At that point the selected item in the list will be used to set the value in the backing bean.
You can also allow for a "no selection" selection. I often do this, where I add an extra selection element to the top of the display list whose data value is "" and whose display value is something like "-------" or "(Please make a selection)".
Incidentally, if you have a selection whose data value is an empty string, you can force the user to make a selection by setting 'required="true"' on the selectOneMenu element. Validators don't work when no value is supplied, but "required=" takes over for that particular case. Not entirely intuitive, but at least it's consistent.
Joined: Apr 10, 2006
sorry again that was not the case,
any way the following link gives better understading of the issue desc.
OK, in that particular case, I'm afraid my response is going to be ....
Never mind. SelectOneMenu is EXACTLY what its name says Select One Menu.
If you remove the selected item from the menu, then you are obliged to change the selection to an item that is on the menu. The whole point of SelectOneMenu is that it restricts the values to a specified list.
Thus, if you modify the list, you need to modify the selection value as well to conform to the list. Since the only way to update the displayed dropdown list is to re-render the dropdown list control, the change to the selected value should have been carried along as part of the re-rendering process.