Primefaces 命令按钮不更新数据表

Primefaces command button does not update datatable

我有 primefaces 命令按钮多次更新问题。命令按钮在表单内,数据表不在。

我试过:

update=":datalist1,form1" 
update=":datalist1 form1" 
update="datalist1 form1"
update=":#{p:component('datalist1')},form1"

form1每次都更新,dattable还是不更新

Version info:
primefaces: 5.3 
jsf: org.glassfish 2.3.0-m04
spring: 4.2.3
and I use cdi for controller beans

页数:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui">

<h:head></h:head>
<body>

<h:form id="form1" >
<h:panelGrid columns="3">
<h:outputLabel value="Name: " for="name" />
<p:inputText id="name" value="#{personelController.personel.adi}" required="true" requiredMessage="Name can not be null" />
<p:message id="nameMsg" for="name" />

<h:outputLabel value="Surname: " for="surname" />
<p:inputText id="surname" value="#{personelController.personel.soyadi}" required="true" requiredMessage="Surname can not be null" />
<p:message id="surnameMsg" for="surname" />

<h:outputLabel value="Age: " for="age" />
<p:inputText id="age" value="#{personelController.personel.yasi}" required="true" requiredMessage="Age  can not be null" />
<p:message id="ageMsg" for="age" />

<h:outputLabel value="Job: " for="job" />
<p:inputText id="job" value="#{personelController.personel.meslek}" required="true" requiredMessage="Job  can not be null" />
<p:message id="jobMsg" for="job" />

<h:outputLabel value="City" for="city" />
<p:inputText id="city" value="#{personelController.personel.sehir}" required="true" requiredMessage="City  can not be null" />
<p:message id="cityMsg" for="city" />

<p:commandButton id="add" value="Add" actionListener="#{personelController.createPersonel()}" update=":datalist1,form1" />
</h:panelGrid>
</h:form>
    <p:dataTable id="datalist1" var="person" value="#{personelController.personels}" resizableColumns="true">
        <f:facet name="header">List of Personel</f:facet>
        <p:column headerText="ID">
            <h:outputText value="#{person.id}" />
        </p:column>
        <p:column headerText="Name">
            <h:outputText value="#{person.adi}" />
        </p:column>
        <p:column headerText="Surname">
            <h:outputText value="#{person.soyadi}" />
        </p:column>
        <p:column headerText="Age">
            <h:outputText value="#{person.yasi}" />
        </p:column>
        <p:column headerText="Job">
            <h:outputText value="#{person.meslek}" />
        </p:column>
        <p:column headerText="City">
            <h:outputText value="#{person.sehir}" />
        </p:column>
    </p:dataTable>

</body>
</html>

Class:

@Named
@SpringViewScoped
public class PersonelController implements Serializable{

    private static final long serialVersionUID = 1L;

    @Inject
    private PersonelService personelService;
    private List<Personel> personels;
    private List<Personel> selectedPersonel;
    private Personel personel;

    @PostConstruct
    public void init(){
        personels=personelService.findAll();
        personel=new Personel();
    }

    public PersonelService getPersonelService() {
        return personelService;
    }

    public void setPersonelService(PersonelService personelService) {
        this.personelService = personelService;
    }

    public List<Personel> getPersonels() {
        return personels;
    }

    public void setPersonels(List<Personel> personels) {
        this.personels = personels;
    }

    public List<Personel> getSelectedPersonel() {
        return selectedPersonel;
    }

    public void setSelectedPersonel(List<Personel> selectedPersonel) {
        this.selectedPersonel = selectedPersonel;
    }

    public Personel getPersonel() {
        return personel;
    }

    public void setPersonel(Personel personel) {
        this.personel = personel;
    }

    public void createPersonel(){
        System.out.println("Personel adding..");
        personelService.create(personel);
        personel=new Personel();
        System.out.println("Personel added");
    }

}

我研究过 primefaces 命令按钮更新,但所有建议对我都不起作用。提前谢谢你

在我看来,它从未将新创建的人员添加到列表中。所以你必须例如说

personels.add(personel);

personels=personelService.findAll();

在 createPersonel() 中,或将 personels 设置为 null 并在 getPersonels() 中执行延迟加载。