Validation messages is shown for SelectOneMenu in case first child is not SelectItems or SelectItem

Details

Description

If SelectOneMenu has child of another type than SelectItems or SelectItem at first place in the children list (e.g. itomahawk jsValueChangeListener), validation of combobox fails with message "Value is not a valid option." Value range is empty in this case because _SelectItemsIterator hasNext() method returns false if first child is not of type SelectItems or SelectItem. It should just skip such children, and should continue looking for values. Right?

In myfaces if i have any type of component like f:param and f:valuechanelistener etc before f:selectitem or f:selectitems SelectItemsIterator and _SelectItemsIterator does not return correct value for hasNext().

I have added the following patch to both the classes SelectItemsIterator and _SelectItemsIterator so that they ignore the children which are not UISelectItem and UISelectItems.

David Brainard
added a comment - 26/Oct/07 22:54 I have checked with the RI impl they dont have this problem.
In myfaces if i have any type of component like f:param and f:valuechanelistener etc before f:selectitem or f:selectitems SelectItemsIterator and _SelectItemsIterator does not return correct value for hasNext().
I have added the following patch to both the classes SelectItemsIterator and _SelectItemsIterator so that they ignore the children which are not UISelectItem and UISelectItems.
if (_childs.hasNext())
{
UIComponent child = (UIComponent) _childs.next();
while(!(child instanceof UISelectItem)
&& !(child instanceof UISelectItems))
{
child = (UIComponent) _childs.next();
}
Pls comment if this approach is not suitable.
i'll add a patch for this soon.

Leonardo Uribe
added a comment - 04/Aug/08 20:41 After checking this issue the solution proposed is correct, but it should be applied on both shared and core projects, for both 1.1 and 1.2 versions.
The normal behavior for this iterator should be as proposed on the solution skip elements that does not inherit form UISelectItem or UISelectItems.
I'll apply this patch soon.

The solution proposed has an small bug, so the final solution committed for skip non UISelectItem or UISelectItems is this:

// When there is other components nested that does
// not extends from UISelectItem or UISelectItems
// the behavior for this iterator is just skip this
// element(s) until an element that extends from these
// classes are found. If there is no more elements
// that conform this condition, just return false.
while (!(child instanceof UISelectItem)
&& !(child instanceof UISelectItems))
{
//Try to skip it
if (_childs.hasNext())

{
//Skip and do the same check
child = (UIComponent) _childs.next();
}

else

{
//End loop, so the final result is return false,
//since there are no more components to iterate.
return false;
}

Leonardo Uribe
added a comment - 04/Aug/08 21:26 The solution proposed has an small bug, so the final solution committed for skip non UISelectItem or UISelectItems is this:
// When there is other components nested that does
// not extends from UISelectItem or UISelectItems
// the behavior for this iterator is just skip this
// element(s) until an element that extends from these
// classes are found. If there is no more elements
// that conform this condition, just return false.
while (!(child instanceof UISelectItem)
&& !(child instanceof UISelectItems))
{
//Try to skip it
if (_childs.hasNext())
{
//Skip and do the same check
child = (UIComponent) _childs.next();
}
else
{
//End loop, so the final result is return false,
//since there are no more components to iterate.
return false;
}
}
Thanks to David Brainard for provide us this patch