根據@flash的回答,我在Employee類(emp類)中實現了轉換器並等於()& hashCode()。 XHTML的
部分:
<my:dropdown label="Employee ID" id="emp" value="#{deliveryPort.emp}" required="false">
<f:selectItem itemValue="#{null}" itemLabel="Selct One"/>
<s:selectItems value="#{deliveryPort.empList}" var="emp" label="# {emp.employeeId} #{ emp.nameFirst}"/>
<f:converter converterId="empConverter" />
</my:dropdown>
EmployeeConverter類別:
package mypackage.converters;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
@FacesConverter("empConverter")
public class EmployeeConverter implements Converter
{
public Object getAsObject(FacesContext context, UIComponent component, String value)
{
return value;
}
public String getAsString(FacesContext context, UIComponent component, Object value)
{
return value.toString();
}
}
Employee類的部分(類EMP的,假想EMPLOYEEID爲String):
public boolean equals(Object other)
{
return other instanceof Employee && (employeeId != null) ? employeeId.equals(((Employee) other).employeeId) : (other == this);
}
public int hashCode()
{
return employeeId != null ? this.getClass().hashCode() + employeeId.hashCode() : super.hashCode();
}
public String toString()
{
return "Employee[" + employeeId + "," + nameFirst + "]";
}
我類似的問題。它爲我工作。
非常感謝您的幫助。這也是一篇很棒的文章。 – user1423793