2

我有一个类似的问题:Primefaces:confirmDialog 中的commandButton 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;
}

有任何想法吗?

谢谢

4

1 回答 1

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

随意恢复。

于 2013-03-11T19:21:31.813 回答