2

我正在尝试使 selectOneMenu 工作。我已经设法让它显示带有过滤器输入的选择,但每次我尝试在那里写一些东西时,一切都会消失。

这是视图中的代码:

<p:selectOneMenu style="width:160px" label="Supervisor" filter="true" filterMatchMode="startsWith" converter="userConverter">
    <f:selectItem itemLabel="Choose..." itemValue="" />
    <f:selectItems value="#{userBean.supervisors}" var="user" itemLabel="#{user.surname} #{user.name}" itemValue="#{user}"/>
</p:selectOneMenu>

userBean.supervisors 传递的值由以下人员提供:

public List<User> getSupervisors() {
    if (supervisors == null) {
        supervisors = userDao.getUsersByRole(Enums.Roles.SUPERVISOR.getValue());
    }
    return supervisors;
}

转换器很简单:

@FacesConverter(forClass = User.class, value="userConverter")
public class UserConverter implements Converter {

@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
    if(value == "") return null;
    // Convert ProjectDetail to its unique String representation.
    User user = (User) value;
    String idAsString = String.valueOf(user.getUserId());
    return idAsString;
}

@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
    // Convert unique String representation of ProjectDetail back to ProjectDetail object.
    Long id = Long.valueOf(value);
    UserDAO userDao = new UserDAO();
    User user = userDao.getUser(id);
    return user;
}
}

如果我将 p:selectOneMenu 更改为 p:selectCheckboxMenu 过滤并且一切正常,那会很有趣。

4

1 回答 1

0

检查此 css 以显示结果:

.ui-selectonemenu-items-wrapper{
    height: auto !important;
}
于 2014-07-01T08:36:51.637 回答