Primefaces删除&确认表列中的对话框 - 更新或冻结问题

时间:2013-03-11 18:59:40

标签: primefaces datatable .refresh

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

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

删除按钮应删除游戏

该按钮会删除游戏但更新不起作用。

  • update =“:form1:overviewTableGame” - >没有反应(没有刷新)

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

表格代码:

<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();
}

selectedGame

private Game selectedGame;

public Game getSelectedGame() {
    return selectedGame;
}

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

有什么想法吗?

由于

1 个答案:

答案 0 :(得分:6)

将对话框与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;
    }
}

随意恢复。