我是java程序员的初学者,使用Netbeans从ERD生成CRUD jsf,并使用bootsfaces显示我的Web UI,但我不知道为什么它只显示值=“1”,如下所示
如下生成的HTML,您可以看到值为“1”& “2”,但正确的值应为“CHI”& “COMP”,如果我使用b:selectOneMenu
<b:selectOneMenu id="deptUnitCode" value="#{isusVpnAppnMastController.selected.deptUnitCode}" label="#{bundle.CreateIsusVpnAppnMastLabel_deptUnitCode}" title="#{bundle.CreateIsusVpnAppnMastTitle_deptUnitCode}" required="true" requiredMessage="#{bundle.CreateIsusVpnAppnMastRequiredMessage_deptUnitCode}">
<f:selectItems value="#{deptUnitController.itemsAvailableSelectOne}"/>
</b:selectOneMenu>
<select id="j_idt13:deptUnitCodeInner" name="j_idt13:deptUnitCodeInner" class="form-control bf-required" title="DeptUnitCode">
<option data-label="---" value="">---</option>
<option data-label="CHI - [CHI]" value="1">CHI - [CHI]</option>
<option data-label="COMP - [COMP]" value="2">COMP - [COMP]</option>
</select>
但如果我改为f:selectOneMenu(即原生的),则生成的HTML是正确的
<h:selectOneMenu id="deptUnitCode" value="#{isusVpnAppnMastController.selected.deptUnitCode}" label="#{bundle.CreateIsusVpnAppnMastLabel_deptUnitCode}" title="#{bundle.CreateIsusVpnAppnMastTitle_deptUnitCode}" required="true" requiredMessage="#{bundle.CreateIsusVpnAppnMastRequiredMessage_deptUnitCode}">
<f:selectItems value="#{deptUnitController.itemsAvailableSelectOne}"/>
</h:selectOneMenu>
<select id="j_idt13:deptUnitCode" name="j_idt13:deptUnitCode" size="1" title="DeptUnitCode"> <option value="">---</option>
<option value="CHI">CHI - [CHI]</option>
<option value="COMP">COMP - [COMP]</option>
</select>
如下所示生成Java控制器,您可以看到itemvalue是Object Class
public static SelectItem[] getSelectItems(List<?> entities, boolean selectOne) {
int size = selectOne ? entities.size() + 1 : entities.size();
SelectItem[] items = new SelectItem[size];
int i = 0;
if (selectOne) {
items[0] = new SelectItem("", "---");
i++;
}
for (Object x : entities) {
items[i++] = new SelectItem(x, x.toString());
}
return items;
}
是否在网址中显示错误:https://showcase.bootsfaces.net/forms/selectOneMenu.jsf
任何有想法解决这个问题的机构而不是投射对象x? 感谢您的关注