我的问题是 Rich Faces 4.1.0 选项列表。我有一个可以填充左右两侧的项目。我无法从右侧(即employeeBean.target)获取数据,我不知道为什么。有人可以看看这段代码并告诉我哪里可能出错了。
看法:
<rich:panel style="width:560px;">
<h:form>
<rich:pickList value="#{employeeBean.target}" var="emp" id="picklist"
sourceCaption="Available" targetCaption="Selected"
orderable="false" converter="employeeConverter">
<f:selectItems value="#{employeeBean.source}" var="employee" itemValue="#{employee}" />
<f:converter converterId="employeeConverter" />
</rich:pickList>
</h:form>
jobcardBean bean = #{employeeBean.target}
</rich:panel>
控制器:
@ManagedBean
@ViewScoped
public class EmployeeBean implements Serializable {
private static final long serialVersionUID = 1L;
List<Employee> source;
List<Employee> target;
public EmployeeBean() {
}
public List<Employee> getSource() {
return new DatabaseBean().getAllEmployees();
}
public void setSource(List<Employee> source) {
this.source = source;
}
public List<Employee> getTarget() {
return target;
}
public void setTarget(List<Employee> target) {
this.target = target;
}
/ * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * **** /
@FacesConverter(value = "employeeConverter")
public class EmployeeConverter implements Converter {
@Override
public Object getAsObject(FacesContext context, UIComponent component, String submittedValue) {
if (submittedValue.trim().equals("")) {
return null;
} else {
return submittedValue.toString();
}
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
if (value == null || value.equals("")) {
return "";
} else {
return String.valueOf(((Employee) value));
}
}
}
模型:
public String toString() {
return getName() + " " + getSurname();
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof Employee)) {
return false;
}
return ((Employee) obj).getName() == this.name && ((Employee) obj).getSurname() == this.surname;
}
@Override
public int hashCode() {
int hash = 1;
return hash * 31 + name.hashCode();
}