Hi,
I have got a selectOnemenu with selectItems populated from an Enum - CodeTyeEnum.
If a code is already saved then the dropdown should default to that code, if no code is saved for that Period a 'Please Select' will be the default value.
Currently what happens is the first time I enter the screen for a Period if the saved code is 'N' then the default value selected and highlighted is 'N'.
If I go back and re enter the screen for a Period with saved code X it is still highlighting 'N' instead of 'X', can anyone see what the issue is?
Following is the xhtml snippet
<h:selectOneMenu id="confirmCode"
binding="#{detail.myCode}"
converter="myCodeConverter"
disabled="#{detail.readOnly}">
<f:selectItems id="myCodeOptions"
value="#{detail.myCodeOptions}" />
</h:selectOneMenu>
The backing bean method is as is as follows
public List getMyCodeOptions() {
Long selectedId = null;
if (getPeriods().size() > 1) {
if (getSelectedPeriodId() == null && "".equals(getSelectedPeriodId())) {
return EnumerationSelectItems.getSelectItems(CodeTypeEnum.class, true, true);
} else {
if (getSelectedPeriodId() != null) {
selectedId = new Long(getSelectedPeriodId());
}
}
} else {
selectedId = getPeriod().getId();
}
if (selectedId == null) {
return EnumerationSelectItems.getSelectItems(CodeTypeEnum.class, true, true);
}
PeriodService service = (PeriodService ) getSpringBean(DATA_SERVICE);
Period period = service.getPeriod(selectedId);
CodeTypeEnum code = period.getCode();
if (code != null) {
boolean isSuspended = ((CodeTypeEnum.SUSPENDED.equals(code))
&& (period.getState() == StateEnum.CONFIRMED));
if ((period.isOnWorklist() && (period.getState() == StateEnum.CONFIRMATION_PENDED))
|| (period.getState() == StateEnum.AWAITING_REASSESSMENT)
|| isSuspended) {
return convertEnumsToSelectItems(CodeTypeEnum.class, code);
}
}
return EnumerationSelectItems.getSelectItems(CodeTypeEnum.class, true, true);
}
/**
*
* @param enumClass
* @param attendanceCode
* @return List of selectItems
*/
private static List convertEnumsToSelectItems(Class enumClass, Enum code) {
List enumList = EnumUtils.getEnumList(CodeTypeEnum.class);
List selectItems = new ArrayList();
String defaultValue = ((StringValuedEnum) code).getValue();
SelectItem selectItem = new SelectItem(code,
defaultValue,
defaultValue);
selectItems.add(selectItem);
Iterator it = enumList.iterator();
while (it.hasNext()) {
Enum enumeration = (Enum) it.next();
String value = null;
StringValuedEnum stringValuedEnum = (StringValuedEnum) enumeration;
value = stringValuedEnum.getValue();
if (!value.equals(defaultValue)) {
SelectItem item = new SelectItem(enumeration,
value,
value);
selectItems.add(item);
}
}
return selectItems;
}