throw new IllegalStateException(msg);
}
// Determine whether option list should be loaded
if (getOptionList().size() == 1) {
Option option = (Option) getOptionList().get(0);
if (option.getValue().equals(Option.EMPTY_OPTION.getValue())) {
// continue and load option list
} else {
// Don't load list
return;
}
} else if (getOptionList().size() > 1) {
// Don't load list
return;
}
DataContext dataContext = DataContext.getThreadDataContext();
List list = Collections.EMPTY_LIST;
if (getSelectQuery() != null) {
list = dataContext.performQuery(getSelectQuery());
} else if (getNamedQuery() != null) {
list = dataContext.performQuery(getNamedQuery());
} else if (getQueryName() != null) {
list = dataContext.performQuery(getQueryName(), getExpireCache());
}
if (isRequired() && getOptionList().isEmpty() || isOptional()) {
getOptionList().add(Option.EMPTY_OPTION);
}
Map cache = new HashMap();
for (int i = 0; i < list.size(); i++) {
Object row = list.get(i);
Object value = null;
Object label = null;
if (row instanceof DataRow) {
DataRow dataRow = (DataRow) row;
if (dataRow.containsKey(getOptionValue())) {
value = dataRow.get(getOptionValue());
} else {
String msg = "no value in dataRow for optionValue: "
+ getOptionValue();
throw new RuntimeException(msg);
}
if (getOptionLabel() != null) {
if (dataRow.containsKey(getOptionLabel())) {
label = dataRow.get(getOptionLabel());
} else {
String msg = "no value in dataRow for optionLabel: "
+ getOptionLabel();
throw new RuntimeException(msg);
}
} else {
label = getDecorator().render(dataRow, getContext());
}
} else {
try {
value = PropertyUtils.getValue(row, getOptionValue(), cache);
if (getOptionLabel() != null) {
label = PropertyUtils.getValue(row, getOptionLabel(), cache);
} else {
label = getDecorator().render(row, getContext());
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
value = (value != null) ? value : "";
label = (label != null) ? label : "";
getOptionList().add(new Option(value.toString(), label.toString()));
}
}