0

我知道这不是错误。但是我需要一个建议,我该怎么做才能不丢失检查行的检查知识?

在 JSF 页面上:

<h:form prependId="false" id="searchUserFormTable" > 
                    <p:dataTable  id="selectUserTable" var="user" 
                    value="#{userListController.lazyDataModel}" paginator="true"
                    paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                    rows="2" paginatorPosition="bottom" rowKey="#{user}"
                    lazy="true"
                    rowsPerPageTemplate="2,10,20,30,40,50"
                    rendered="#{userListController.lazyDataModel != null}" selection="#{systemMessageEditController.receiverList}"
                    scrollable="true" scrollHeight="250" resizableColumns="false" >


                    <p:column selectionMode="multiple" width="18" />

                    <f:facet name="header">
                        <h:outputText value=" Users (#{userListController.lazyDataModel.rowCount})"  />
                    </f:facet>

                    <p:column filterBy="#{user.name}" headerText="Name" filterMatchMode="contains" width="80">
                        #{user.name}
                    </p:column>
                    <p:column filterBy="#{user.surname}" headerText="Surname" filterMatchMode="contains" width="80">
                        #{user.surname}
                    </p:column>   
                    <p:column headerText="Gender" width="80">
                        #{user.gender}
                    </p:column>

                    <p:column headerText="City" width="80">                             
                        #{user.address.city.name}
                    </p:column>

                    <p:column headerText="Status" width="80">                               
                        #{user.userStatus}
                    </p:column>

                    <p:column headerText="User Detail" width="80">
                        <h:link value="User Detail" outcome="/view/admin/usermanagement/userInfo.jsf">
                            <f:param name="userId" value="#{user.id}" />
                        </h:link>
                    </p:column>



                </p:dataTable>
                        <p:commandButton value="Tamam" oncomplete="userListDlg.hide();" update=":newMessageForm"></p:commandButton>
            </h:form>

所有控制器:

    @ManagedBean(name="systemMessageEditController")
@ViewScoped
public class SystemMessageEditController {

    @ManagedProperty(value = "#{systemMessageService}")
    SystemMessageService systemMessageService;

    @ManagedProperty(value = "#{securityBean}")
    SecurityBean securityBean;

    @ManagedProperty(value = "#{systemMessageReceiverService}")
    SystemMessageReceiverService systemMessageReceiverService;

    @ManagedProperty(value = "#{systemMessageAnswerService}")
    SystemMessageAnswerService systemMessageAnswerService;

    private SystemMessage systemMessage = new SystemMessage();

    private SystemMessageAnswer systemMessageAnswer = new SystemMessageAnswer();

    private SystemMessageReceiver systemMessageReceiver = new SystemMessageReceiver();

    private User[] receiverList;
    private boolean dummy;


    public void prepareToEdit(){
        systemMessage = systemMessageService.findById(systemMessage.getId());
    }

    public void prepareToSendMessage(){
        systemMessage = new SystemMessage();
        receiverList = null ;

    }

    public void sendMessage(){
        if(Util.isNotNull(systemMessage.getTitle())){
            boolean success = false;
            systemMessageAnswer.setUser(securityBean.getUser());
            systemMessage.getSystemMessageAnswerList().add(systemMessageAnswer);
            systemMessage.setUserSender(securityBean.getUser());
            systemMessageAnswer.setSystemMessage(systemMessage);
            if(!systemMessage.isSendAll()){
                addMessageReceiver();   
            }


            systemMessage = systemMessageService.save(systemMessage);

            systemMessageAnswer = new SystemMessageAnswer();

            success = true;
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, FacesUtils.getMessageByKey("systemmessage.send.success"), FacesUtils.getMessageByKey("systemmessage.send.success"));
            FacesContext.getCurrentInstance().addMessage("", message);
            RequestContext context = RequestContext.getCurrentInstance();
            context.addCallbackParam("success", success);
        }
        else{
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, FacesUtils.getMessageByKey("systemmessage.null.title"), FacesUtils.getMessageByKey("systemmessage.null.title"));
            FacesContext.getCurrentInstance().addMessage("", message);
        }
    }

    public void setRead(SystemMessage message){
        message.setReaded(true);
        systemMessageService.save(message);
    }


    public void addMessageReceiver(){
        for(User user : receiverList){
            SystemMessageReceiver messageReceiver = new SystemMessageReceiver();
            messageReceiver.setReceiver(user);
            messageReceiver.setSystemMessage(systemMessage);
            messageReceiver.setReaded(false);
            systemMessage.getSystemMessageReceiverList().add(messageReceiver);
        }

    }

    public void deleteMessage(){
        boolean success = false;
        systemMessageService.delete(systemMessageService.findById(systemMessage.getId()));

        success = true;
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, FacesUtils.getMessageByKey("systemmessage.delete.success"), FacesUtils.getMessageByKey("systemmessage.delete.success"));
        FacesContext.getCurrentInstance().addMessage("", message);
        RequestContext context = RequestContext.getCurrentInstance();
        context.addCallbackParam("success", success);
    }
    public void sendMessageAnswer(){
        systemMessageAnswer.setUser(securityBean.getUser());
        systemMessageAnswer.setSystemMessage(systemMessage);
        systemMessageAnswerService.save(systemMessageAnswer);

        if(!systemMessage.isSendAll()){
            systemMessage.setSystemMessageReceiverList(systemMessageService.getReceiverListOfMessage(systemMessage));
            for(SystemMessageReceiver systemMessageReceiver : systemMessage.getSystemMessageReceiverList()){
                if(!systemMessageReceiver.getReceiver().getId().equals(securityBean.getUser().getId())){
                    systemMessageReceiver.setReaded(false);
                    systemMessageReceiver.setShowed(false);
                    systemMessageReceiverService.save(systemMessageReceiver);
                }
            }
        }

        systemMessage.getSystemMessageAnswerList().add(systemMessageAnswer);

        systemMessageAnswer = new SystemMessageAnswer();
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, FacesUtils.getMessageByKey("systemmessage.send.success"), FacesUtils.getMessageByKey("systemmessage.send.success"));
        FacesContext.getCurrentInstance().addMessage("", message);
        RequestContext context = RequestContext.getCurrentInstance();
        context.addCallbackParam("success", true);
    }



    public SystemMessageService getSystemMessageService() {
        return systemMessageService;
    }

    public void setSystemMessageService(SystemMessageService systemMessageService) {
        this.systemMessageService = systemMessageService;
    }

    public SystemMessage getSystemMessage() {
        return systemMessage;
    }

    public void setSystemMessage(SystemMessage systemMessage) {
        ArrayList<String> fetchedAttributes = new ArrayList<String>();
        fetchedAttributes.add("systemMessageAnswerList");
        this.systemMessage = systemMessageService.loadWithFetchedAttributes(systemMessage.getId(),fetchedAttributes);
    }

    public SystemMessageAnswer getSystemMessageAnswer() {
        return systemMessageAnswer;
    }

    public void setSystemMessageAnswer(SystemMessageAnswer systemMessageAnswer) {
        this.systemMessageAnswer = systemMessageAnswer;
    }
    public SecurityBean getSecurityBean() {
        return securityBean;
    }
    public void setSecurityBean(SecurityBean securityBean) {
        this.securityBean = securityBean;
    }
    public SystemMessageReceiverService getSystemMessageReceiverService() {
        return systemMessageReceiverService;
    }
    public void setSystemMessageReceiverService(
            SystemMessageReceiverService systemMessageReceiverService) {
        this.systemMessageReceiverService = systemMessageReceiverService;
    }
    public SystemMessageAnswerService getSystemMessageAnswerService() {
        return systemMessageAnswerService;
    }
    public void setSystemMessageAnswerService(
            SystemMessageAnswerService systemMessageAnswerService) {
        this.systemMessageAnswerService = systemMessageAnswerService;
    }
    public SystemMessageReceiver getSystemMessageReceiver() {
        return systemMessageReceiver;
    }
    public void setSystemMessageReceiver(SystemMessageReceiver systemMessageReceiver) {
        this.systemMessageReceiver = systemMessageReceiver;
    }
    public User[] getReceiverList() {
        return receiverList;
    }
    public void setReceiverList(User[] receiverList) {
        this.receiverList = receiverList;
    }

我在将一个分页号跳转到另一个时丢失了检查信息,当我检查一些行时,然后在数据表中跳转另一个分页号,然后返回旧的分页号,我丢失了检查的信息,我发现没有任何变化。

4

3 回答 3

1

这是如何@ViewScoped工作的。请参阅 BalusC 的以下答案

只要您与同一个视图交互(即您在 bean 操作方法中返回 void 或 null),视图范围的 bean 就会存在。当您导航到另一个视图时,例如通过单击链接或返回不同的操作结果,则视图范围的 bean 将在渲染响应结束时被丢弃,并且在下一个请求中不可用。

这解释了在像你这样的情况下(我刚刚在你的一个评论中读到你在失去选择之前跳转到另一个页面,你也应该在你的问题中注意到这一点!)bean被破坏了,所以当你导航回你的dataTable查看它再次被重建。这就是receiverList空=>没有选择的原因。

如果您想在不同视图之间导航时保​​存数据,请使用范围比 @ViewScoped 更宽的 bean,或者只是将选择保存到数据库中的表中。

编辑

问题可能出在您的rowKey属性中。在当前代码中,它指向用户对象,在这种情况下,请确保此对象具有正确的hashCode,equalstoString实现。如果user该类实际上有一个键或其他东西,则更rowKey改为rowKey="#{user.id}".

于 2013-01-09T09:39:57.163 回答
0

检查陈列柜。我认为它就像你想要的那样工作。

于 2013-01-09T09:15:34.057 回答
0

您可能正在通过 ajax 请求发送数据,您应该确保它是processdataTable 本身

于 2013-01-09T09:22:43.490 回答