in empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/SelectInputControl.java [219:306]
public void syncOptions(UISelectOne input, TextResolver textResolver, InputInfo ii)
{
// get the options
Options options = ii.getOptions();
if (options==null)
{ // clear or not?
if (ii.getValue(false)!=null)
log.warn("No options have been set for column {}", ii.getColumn().getName());
else
input.getChildren().clear();
return;
}
Object currentValue = ii.getValue(true);
boolean hasEmpty = isEmptyEntryRequired(input, options, ii, currentValue);
// boolean isInsideUIData = ii.isInsideUIData();
// Compare child-items with options
Iterator<OptionEntry> ioe = options.iterator();
OptionEntry oe = (ioe.hasNext() ? ioe.next() : null);
List<UIComponent> childList = input.getChildren();
Iterator<UIComponent> ico = childList.iterator();
int lastIndex = 0;
boolean emptyPresent = false;
while (ico.hasNext())
{
lastIndex++;
UIComponent co = ico.next();
if (!(co instanceof UISelectItem))
continue;
UISelectItem si = (UISelectItem) co;
Object ov = si.getItemValue();
if (ObjectUtils.isEmpty(ov) && hasEmpty)
{ emptyPresent = true;
continue;
}
// skip inactive
while (oe!=null && !oe.isActive())
{ // check for current
if (ObjectUtils.compareEqual(oe.getValue(), currentValue))
break;
// next oe
oe = (ioe.hasNext() ? ioe.next() : null);
}
if (oe == null)
{ // remove obsolete items
lastIndex--;
for (int index = childList.size() - 1; index >= lastIndex; index--)
childList.remove(index);
// done
return;
}
if (ObjectUtils.compareEqual(ov, oe.getValue()))
{ // next
String label = oe.getText();
si.setItemLabel(textResolver.resolveText(label));
oe = (ioe.hasNext() ? ioe.next() : null);
continue;
}
// Not equal - do a full reload
input.getChildren().clear();
if (hasEmpty) {
// add empty entry
addSelectItem(input, textResolver, new OptionEntry("", getNullText(ii)));
}
for (OptionEntry opt : options)
{ // Option entries
if (opt.isActive() || ObjectUtils.compareEqual(opt.getValue(), currentValue))
{ // add active or current item
addSelectItem(input, textResolver, opt);
}
}
// done
return;
}
// check empty entry
if (hasEmpty && !emptyPresent)
{ // add missing empty entry
addSelectItem(input, textResolver, new OptionEntry("", getNullText(ii)), 0);
}
// Are there any items left?
while (oe != null)
{ // add missing item
if (oe.isActive() || ObjectUtils.compareEqual(oe.getValue(), currentValue))
{ // add item
addSelectItem(input, textResolver, oe);
}
oe = (ioe.hasNext() ? ioe.next() : null);
}
}