如何检索可编辑数据表中存在的多个自动完成值

时间:2017-03-21 11:15:08

标签: java jsf primefaces jsf-2

我有一个数据表,其中一列包含多个自动完成

    <h:form id="form">
        <p:dataTable id="dTable" var="il"
            value="#{assignIssueController.issueList}" editable="true"
            style="margin-bottom:20px">
            <f:facet name="header">
                Assign Issues
            </f:facet>

            <p:ajax event="rowEdit" listener="#{assignIssueController.onRowEdit}"
                update=":form:dTable" />
            <p:ajax event="rowEditCancel" listener="#{assignIssueController.onRowCancel}" />

            <p:column headerText="Issue Number">
                <h:outputText value="#{il[0]}" />
            </p:column>

            <p:column headerText="Issue Discribtion">
                <h:outputText value="#{il[1]}" />
            </p:column>

            <p:column headerText="Issue Type">
                <h:outputText value="#{il[2]}" />
            </p:column>

            <p:column headerText="Updated By">
                <h:outputText value="#{il[4]}" />
            </p:column>
            <p:column style="display: none">
                <f:facet name="output">
                    <h:outputText value="#{il[5]}" />
                </f:facet>
            </p:column>

            <p:column headerText="Updated By">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{il[3]}" id="userIdTest" />
                    </f:facet>
                    <f:facet name="input">
                        <p:autoComplete id="themes" multiple="true"
                            value="#{assignIssueController.selectedUserList}" completeMethod="#{assignIssueController.complete}"
                            var="usr" itemLabel="#{usr.userId}" itemValue="#{usr}" converter="userConverter"
                            forceSelection="true">
                        </p:autoComplete>
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column style="width:32px">
                <p:rowEditor />
            </p:column>
        </p:dataTable>
    </h:form>

我的Converter-userConverter

@ManagedBean(name = "userConverter")
@RequestScoped
@FacesConverter(value = "userConverter")
public class UserConverter implements Converter {
    public static Logger logger = Logger.getLogger(UserConverter.class);

    @ManagedProperty(value = "#{issueBoImpl}")
    private IssueBo issueBo;

    public IssueBo getIssueBo() {
        return issueBo;
    }

    public void setIssueBo(IssueBo issueBo) {
        this.issueBo = issueBo;
    }

    public List<Users> usersList;

    public List<Users> getUsersList() {
        return usersList;
    }

    public void setUsersList(List<Users> usersList) {
        this.usersList = usersList;
    }

    @SuppressWarnings("unchecked")
    @Override
    public Object getAsObject(FacesContext arg0, UIComponent arg1,
            String submittedValue) {
        logger.debug("Entering in getAsObject() method");
        if (submittedValue.trim().equals("")) {
            logger.debug("Exiting from getAsObject() method");
            return null;
        } else {
            try {
                //int number = Integer.parseInt(submittedValue);

                usersList = issueBo.getAllUser();

                for (Users u : usersList) {

            if (u.getUserId() == Integer.parseInt(submittedValue)) {
                        return u;
                    }
                }
                logger.debug("Exiting from getAsObject() method");
            } catch (Exception e) {
                logger.error("Exception in getAsObject() ", e);
                throw new ConverterException(new FacesMessage(
                        FacesMessage.SEVERITY_ERROR, "Conversion Error",
                        "Email Id Does Not Exist."));
            }
        }
        logger.debug("Exiting from getAsObject() method");
        return null;
    }

    @Override
    public String getAsString(FacesContext arg0, UIComponent arg1, Object value) {
        logger.debug("Entering in getAsString() method");
        if (value == null || value.equals("")) {
            logger.debug("Exiting from getAsString() method");
            return "";
        } else {
            logger.debug("Exiting from getAsString() method");
            return String.valueOf(((Users) value).getId());
        }
    }
}

我的控制器类

@ManagedBean(name = "assignIssueController")
@ViewScoped
public class AssignIssueController implements Serializable {
    public static Logger logger = Logger
            .getLogger(AssignIssueController.class);

    @ManagedProperty(value = "#{issueBoImpl}")
    private IssueBo issueBo;
    @ManagedProperty(value = "#{assignIssueBoImpl}")
    private AssignIssueBo assignIssueBo;
    @ManagedProperty(value = "#{usersBoImpl}")
    private UsersBo usersBo;

    private List<Users> userList;
    private List<Object> issueList;
    private List<Users> selectedUserList;

    private int id;

    @PostConstruct
    public void init() {
        issueList = assignIssueBo.getIssueListForAssigingIssue();
    }

    public void onRowEdit(RowEditEvent event) {
         System.out.println(event.getObject());
         System.out.println("----------------------->>>>>>>>>>>>>"+selectedUserList);

         Object[] obj = (Object[]) event.getObject();
         String issueNum = obj[0].toString();
         String issueDesc = obj[1].toString();
         int issueStatusId = Integer.valueOf(obj[5].toString());
         assignIssueBo.assignUpdateIssueToUsers(issueNum, issueDesc, id,issueStatusId);
         issueList = assignIssueBo.getIssueListForAssigingIssue();
    }

    public void onRowCancel(RowEditEvent event) {
        System.out.println(event.getObject());
         System.out.println("----------------------->>>>>>>>>>>>>");
    }

    public List<Users> complete(String query) {
        logger.debug("Entering in complete() method");

        List<Users> userNameList = usersBo.getUserNameList(query);

         List<Users> filteredList = new ArrayList<Users>();

            for (int i = 0; i < userNameList.size(); i++) {
                Users userObj = userNameList.get(i);
                if(userObj.getUserId().toLowerCase().startsWith(query)) {
                    filteredList.add(userObj);
                }
            }
            return filteredList;
    }

    public IssueBo getIssueBo() {
        return issueBo;
    }

    public void setIssueBo(IssueBo issueBo) {
        this.issueBo = issueBo;
    }

    public AssignIssueBo getAssignIssueBo() {
        return assignIssueBo;
    }

    public void setAssignIssueBo(AssignIssueBo assignIssueBo) {
        this.assignIssueBo = assignIssueBo;
    }

    public List<Object> getIssueList() {
        return issueList;
    }

    public void setIssueList(List<Object> issueList) {
        this.issueList = issueList;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public List<Users> getUserList() {
        return issueBo.getAllUser();
    }

    public void setUserList(List<Users> userList) {
        this.userList = userList;
    }

    public UsersBo getUsersBo() {
        return usersBo;
    }

    public void setUsersBo(UsersBo usersBo) {
        this.usersBo = usersBo;
    }

    public List<Users> getSelectedUserList() {
        return selectedUserList;
    }

    public void setSelectedUserList(List<Users> selectedUserList) {
        this.selectedUserList = selectedUserList;
    }


}

此处的问题是在自动完成中选择值后,selectedUserList仍然显示为null。我如何获取这些多个值?

0 个答案:

没有答案