【问题标题】:Primefaces Delete & Confirm Dialog inside table column - Update or Freeze Issue表列内的 Primefaces 删除和确认对话框 - 更新或冻结问题
【发布时间】:2013-03-11 18:59:39
【问题描述】:

我有一个类似的问题:Primefaces: commandButton in confirmDialog cannot update datatable in the same form

我有一张带游戏的桌子。最后一列有 2 个按钮:删除和详细信息。

删除按钮应该删除游戏

该按钮确实删除了游戏,但更新不起作用。

  • update=":form1:overviewTableGame" --> 无反应(无刷新)

  • update="@form" --> 更新执行(表刷新),但整个屏幕被锁定。我认为由于这个事实,包含对话框的表单已更新...

表格代码:

<h:form id="form1">
        <p:messages id="messages" showDetail="true" autoUpdate="true"
            closable="true" />

        <p:dataTable id="overviewTableGame" var="game" value="#{gameMB.list}">
            <p:column headerText="#{msg.ID}" sortBy="#{game.id}">
                <h:outputText value="#{game.id}" />
            </p:column>

            <p:column headerText="#{msg.NAME}" sortBy="#{game.name}">
                <h:outputText value="#{game.name}" />
            </p:column>

            <p:column headerText="#{msg.DESCRIPTION}"
                sortBy="#{game.description}">
                <h:outputText value="#{game.description}" />
            </p:column>

            <p:column headerText="#{msg.ADMIN}" sortBy="#{game.admin.firstname}">
                <h:outputText value="#{game.admin.firstname}" />
            </p:column>

            <p:column headerText="#{msg.ACTION}">
                <p:commandButton id="commandButtonDELETE" value="löschen"
                    onclick="confirmation.show()" type="button"
                    update=":form1:display">
                    <f:setPropertyActionListener value="#{game}"
                        target="#{gameMB.selectedGame}" />
                </p:commandButton>

                <p:commandButton id="commandButtonDETAIL" value="detail"
                    action="#{gameMB.details()}">
                    <f:param name="id" value="#{game.id}" />
                </p:commandButton>
            </p:column>
        </p:dataTable>

        <p:confirmDialog id="confirmDialog"
            message="Are you sure about destroying the world?"
            header="Initiating destroy process" severity="alert"
            widgetVar="confirmation">


            <h:panelGrid id="display" columns="2" cellpadding="4"
                style="margin:0 auto;">

                <h:outputText value="Name:" />
                <h:outputText value="#{gameMB.selectedGame.name}"
                    style="font-weight:bold" />

                <p:commandButton id="confirm" value="Yes Sure"
                    oncomplete="confirmation.hide()"
                    actionListener="#{gameMB.delete(gameMB.selectedGame)}"
                    update=":form1:overviewTableGame">
                </p:commandButton>
            </h:panelGrid>

            <p:commandButton id="decline" value="Not Yet"
                onclick="confirmation.hide()" type="button" />
        </p:confirmDialog>

    </h:form>

删除方法:

public void delete(Game game) {
    //FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,"DELETE", "Game Deleted!"));
    System.out.println("==================");
    System.out.println(game);
    getGameService().removeGame(game);
    //this.gameList = gameService.listAllGames();
}

选中的游戏

private Game selectedGame;

public Game getSelectedGame() {
    return selectedGame;
}

public void setSelectedGame(Game selectedGame) {
    this.selectedGame = selectedGame;
}

有什么想法吗?

谢谢

【问题讨论】:

    标签: primefaces datatable .refresh


    【解决方案1】:

    将您的对话框与p:dataTable 分开。以下代码正在运行:

    xhtml:

    <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui" template="/WEB-INF/templates/globalTemplate.xhtml">
    
        <ui:define name="title">15344819</ui:define>
        <ui:define name="content">
            <p:growl id="growl" showDetail="true" />
    
            <h:form id="form">
                <p:dataTable id="students" value="#{so15344819.students}" var="student">
                    <p:column>
                            <p:commandButton id="selectButton" update=":form:display" oncomplete="studentDialog.show()" icon="ui-icon-search" title="View">
                               <f:setPropertyActionListener value="#{student}" target="#{so15344819.selectedStudent}" />
                           </p:commandButton>
                       </p:column>
                </p:dataTable>
    
                <p:dialog header="Student Detail" widgetVar="studentDialog" resizable="false" id="studentDlg"
                                showEffect="fade" hideEffect="explode" modal="true">
    
                        <h:panelGrid id="display" columns="2" cellpadding="4" style="margin:0 auto;">
    
                            <h:outputText value="Name:" />
                            <h:outputText value="#{so15344819.selectedStudent.name}" style="font-weight:bold"/>                                               
                            <p:commandButton id="deleteButton" actionListener="#{so15344819.delete(so15344819.selectedStudent)}" oncomplete="studentDialog.hide()" 
                                update=":form:students" value="Delete"/>
                            <p:commandButton id="cancelButton" onclick="studentDialog.hide()" value="Cancel"/>
                        </h:panelGrid>
    
                    </p:dialog>
            </h:form>
        </ui:define>
    
    </ui:composition>
    

    托管 bean:

    package app.so.dev.web.controller;
    
    import java.io.Serializable;
    import java.util.ArrayList;
    import java.util.List;
    
    import javax.annotation.PostConstruct;
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.ViewScoped;
    
    import app.so.dev.web.model.Student;
    
    @ManagedBean(name = "so15344819")
    @ViewScoped
    public class SO15344819 implements Serializable {
    
        private static final long serialVersionUID = 6686378446131077581L;
        private List<Student> students;
        private Student selectedStudent;
    
        @PostConstruct
        public void init() {
            students = new ArrayList<Student>();
            students.add(new Student("Student 1"));
            students.add(new Student("Student 2"));
        }
    
        public void delete(Student student) {
            System.out.println("==================");
            System.out.println(student);
            students.remove(student);
        }
    
        public List<Student> getStudents() {
            return students;
        }
    
        public void setStudents(List<Student> students) {
            this.students = students;
        }
    
        public Student getSelectedStudent() {
            return selectedStudent;
        }
    
        public void setSelectedStudent(Student selectedStudent) {
            this.selectedStudent = selectedStudent;
        }
    }
    

    随时恢复。

    【讨论】:

    • 谢谢! #{so15344819.students} 在哪里定义?正如你在上面看到的,我给了我的 thable 价值“游戏”。好的..托管bean...我要尝试...
    • OK 问题是:在我的对话框中(调用删除方法的地方),没有 selectedGame。我在 bean 中有正确的 get/set 方法。游戏/学生如何将 oh 传递到调用删除方法的对话框?我将在我的问题中编辑代码。
    • @user2158143 selectedStudent 是从commandLink 设置的,它通过f:setPropertyActionListener 从其oncomplete 打开对话框。
    • ok... ActionListener 如何知道选择哪个 Student?
    • @user2158143 你知道f:setPropertyActionListener 的工作原理吗?
    猜你喜欢
    • 2017-09-07
    • 2018-03-04
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 2019-02-11
    • 2014-04-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多