0

谁能告诉我如何为primefaces下拉菜单设置默认值。默认值将来自数据表..

<h:outputLabel for="leaveType" value="Type of Leave *:" styleClass="tLabel"/>
<p:selectOneMenu id="leaveType" value="#{leaveBean.selectedLeave.leaveType}" disabled="#{leaveBean.selectedLeave.status!='Pending'}" >
<f:selectItem itemLabel="#{leaveBean.selectedLeave.leaveType}" itemValue="" />
<f:selectItems value="#{leaveBean.leaveDTO.infoBeanList}" var="lType" itemValue="#{lType.leaveTypeCode}@#{lType.leaveType}" itemLabel="#{lType.leaveType}" />
</p:selectOneMenu>
4

1 回答 1

0

你可以用这个。

public static SelectItem[] getSelectItems(List<?> entities, boolean selectOne) {
    int size = selectOne ? entities.size() + 1 : entities.size();
    SelectItem[] items = new SelectItem[size];
   int i =0;
    for (Object x : entities) {
      items[i++] = new SelectItem(x, x.toString());
    }
    return items;
  }

List<?> entities将是列表结果。

然后确保您的实体类中有以下代码。

@Override
  public String toString() {
    return this.name;
  }
于 2013-10-30T06:08:55.780 回答