Rich Faces 4.1.0选项列表

时间:2012-06-09 19:30:12

标签: richfaces

我的问题在于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();
}

1 个答案:

答案 0 :(得分:0)

我的问题在于我的转换器。这里的getAsObject接受一个字符串并传递一个字符串。该方法将编译但不做任何有用的事情。我通过让getAsObject返回我的模型bean对象而不仅仅是一个字符串来解决这个问题。