我有2个相互关联的数据库表;
员工和联系方式
我想为Employee创建一个下拉菜单,并显示Employee的名字和姓氏,它们是Contact表中的一列 .
<h:selectOneMenu id="employeeDropdown" value="#{employeeController.activeEmployee}">
<s:selectItems id="activeEmployeeList" value="#{employeeController.activeEmployees}" var="emp" itemValue = "#{emp}" label="#{emp.contact.firstName}" />
</h:selectOneMenu>
联系表允许第一个名称列和姓氏列为空,因为它允许空字符串selectItems上显示的某些值为空 .
如何防止显示/呈现这些空名或空名?
1 回答
就像@ subodh-joshi所说的那样,你可以在没有姓或名的
EmployeeController
员工的getActiveEmployees
方法中过滤:或者更好,你可以返回
List<SelectItem>
:返回
List
的SelectItem
,无需使用f:selectItems
的itemValue
和itemLabel
属性 .