更新属性似乎不起作用

时间:2017-10-17 18:28:14

标签: primefaces

我有一个数据表,其中的对话框形式嵌套在tabView标签中.... 数据表的每一行都有按钮,用于编辑和显示对话框形式的数据...但是当我点击编辑或显示按钮时,它不会填写表格...而且我不知道更新有什么问题属性....

我还尝试在创建和更新过程之后通过在表单commanButton中设置更新属性来更新数据表,但似乎缺少某些内容......

我也访问了此链接... update-form-on-hcommandbutton-action 它似乎在我的情况下不起作用...也许是因为更新属性没有设置corectly。 当我删除tabView,layout和LayoutUnit标签时,它可以正常工作

这是我的index.xhtml代码:

<h:body>
    <ui:composition template="/template.xhtml">
        <ui:define name="content">
            <f:view>
                    <p:tabView id="tout">
                        <p:tab title="Identite" id="test">
                            <p:layout style="min-width:400px;min-height:450px;" id="change">


                                <p:layoutUnit position="center" id="tester">
                                    /* this Dialog form is for creating a new Antecedent*/
                                    <p:dialog showEffect="drop" hideEffect="drop" id="creation" widgetVar="creation" header="Enregistrer locataire">
                                        <h:form id="creer">
                                            <center>
                                                <p:panelGrid columns="4">

                                                    <p:outputLabel value="DateDiagnostic:" for="dateDiagnostic" />
                                                    <p:inputText id="dateDiagnostic" value="#{antecedentMBean.antecedent.dateDiagnostic}" title="DateDiagnostic" >
                                                        <f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss" />
                                                    </p:inputText>
                                                    <p:outputLabel value="DateGuerison:" for="dateGuerison" />
                                                    <p:inputText id="dateGuerison" value="#{antecedentMBean.antecedent.dateGuerison}" title="DateGuerison" >
                                                        <f:convertDateTime pattern="MM/dd/yyyy" />
                                                    </p:inputText>
                                                    <p:outputLabel value="Allergies:" for="allergies" />
                                                    <p:inputText id="allergies" value="#{antecedentMBean.antecedent.allergies}" title="Allergies" />
                                                    <p:outputLabel value="Therapie:" for="therapie" />
                                                    <p:inputText id="therapie" value="#{antecedentMBean.antecedent.therapie}" title="Therapie" />

                                                </p:panelGrid>
                                                <p:panelGrid columns="1">
                                                    <p:outputLabel value="Diagnostique:" for="diagnostique" />

                                                    <p:inputTextarea id="diagnostique" value="#{antecedentMBean.antecedent.diagnostique}" title="Diagnostique" autoResize="false" rows="6" cols="83"/>
                                                </p:panelGrid>
                                                <hr/>
                                            </center>
                                            <center>
                                                <p:button icon="fa fa-close" value="Fermer" onclick="PF('creation').hide();
                                                        return false" />
                                                <p:commandButton icon="fa fa-trash" id="effacer" value="Effacer" type="reset"/>
                                                <p:commandButton icon="fa fa-save" value="Enregistrer" action="#{antecedentMBean.createAntecedent()}" 
                                                        update=":formulaire:tbl"          oncomplete="PF('creation').hide()" />
                                            </center>
                                        </h:form>
                                    </p:dialog>



                                    <h:form id="formulaire">
                                    /* this Dialog form is for etiting */
                                        <p:dialog showEffect="size" id="modif" hideEffect="size" widgetVar="modif" header="Modification">
                                            <p:outputPanel id="repere" style="text-align:center;">
                                                <center>
                                                    <p:panelGrid columns="4">

                                                        <p:outputLabel value="DateDiagnostic:" for="dateDiagnostic" />
                                                        <p:inputText id="dateDiagnostic" value="#{antecedentMBean.antecedent.dateDiagnostic}" title="DateDiagnostic" >
                                                            <f:convertDateTime pattern="MM/dd/yyyy" />
                                                        </p:inputText>
                                                        <p:outputLabel value="DateGuerison:" for="dateGuerison" />
                                                        <p:inputText id="dateGuerison" value="#{antecedentMBean.antecedent.dateGuerison}" title="DateGuerison" >
                                                            <f:convertDateTime pattern="MM/dd/yyyy" />
                                                        </p:inputText>
                                                        <p:outputLabel value="Allergies:" for="allergies" />
                                                        <p:inputText id="allergies" value="#{antecedentMBean.antecedent.allergies}" title="Allergies" />
                                                        <p:outputLabel value="Therapie:" for="therapie" />
                                                        <p:inputText id="therapie" value="#{antecedentMBean.antecedent.therapie}" title="Therapie" />

                                                    </p:panelGrid>
                                                    <p:panelGrid columns="1">
                                                        <p:outputLabel value="Diagnostique:" for="diagnostique" />

                                                        <p:inputTextarea id="diagnostique" value="#{antecedentMBean.antecedent.diagnostique}" title="Diagnostique" autoResize="false" rows="6" cols="83"/>
                                                    </p:panelGrid>
                                                    <hr/>
                                                </center>
                                                <center>
                                                    <p:button icon="fa fa-close" value="Fermer" onclick="PF('modif').hide();
                                                            return false" />
                                                    <p:commandButton icon="fa fa-trash" id="effacer" value="Effacer" type="reset"/>
                                                    <p:commandButton icon="fa fa-pencil" value="Modifier" action="#{antecedentMBean.updateAntecedent()}" 
                                                                     update=":formulaire:tbl"  onclick="PF('modif').hide()" />
                                                </center>
                                            </p:outputPanel>
                                        </p:dialog>
                                        /* this Dialog form is for displaying a row details */
                                        <p:dialog showEffect="size" hideEffect="size" id="voir" widgetVar="voir" header="Modification">
                                            <p:outputPanel id="view" style="text-align:center;">
                                                <center>
                                                    <p:panelGrid columns="4">
                                                        <p:outputLabel value="IdAntecedent:"/>
                                                        <h:outputText value="#{antecedentMBean.antecedent.idAntecedent}" title="IdAntecedent"/>
                                                        <p:outputLabel value="DateDiagnostic:"/>
                                                        <h:outputText value="#{antecedentMBean.antecedent.dateDiagnostic}" title="DateDiagnostic">
                                                            <f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss" />
                                                        </h:outputText>
                                                        <p:outputLabel value="DateGuerison:"/>
                                                        <h:outputText value="#{antecedentMBean.antecedent.dateGuerison}" title="DateGuerison">
                                                            <f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss" />
                                                        </h:outputText>
                                                        <p:outputLabel value="Allergies:"/>
                                                        <h:outputText value="#{antecedentMBean.antecedent.allergies}" title="Allergies"/>
                                                        <p:outputLabel value="Therapie:"/>
                                                        <h:outputText value="#{antecedentMBean.antecedent.therapie}" title="Therapie"/>
                                                        <p:outputLabel value="Diagnostique:"/>
                                                        <h:outputText value="#{antecedentMBean.antecedent.diagnostique}" title="Diagnostique"/>
                                                        <p:outputLabel value="CreerPar:"/>
                                                        <h:outputText value="#{antecedentMBean.antecedent.creerPar}" title="CreerPar"/>
                                                        <p:outputLabel 
                                                           <p:outputLabel value="DateCreer:"/>
                                                        <h:outputText value="#{antecedentMBean.antecedent.dateCreer}" title="DateCreer">
                                                            <f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss" />
                                                        </h:outputText>
                                                        <p:outputLabel value="MajPar:"/>
                                                        <h:outputText value="#{antecedentMBean.antecedent.majPar}" title="MajPar"/>
                                                        <p:outputLabel value="DateMaj:"/>
                                                        <h:outputText value="#{antecedentMBean.antecedent.dateMaj}" title="DateMaj">
                                                            <f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss" />
                                                        </h:outputText>
                                                        <p:outputLabel value="IdPatient:"/>
                                                        <h:outputText value="#{antecedentMBean.antecedent.idPatient.prenom}" title="IdPatient"/>
                                                    </p:panelGrid>
                                                    <hr/>
                                                </center>
                                                <p:button icon="fa fa-close" value="Fermer" onclick="PF('voir').hide();
                                                            return false" />
                                            </p:outputPanel>
                                        </p:dialog>

                                        /* this commandButton display the create form */
                                        <p:commandButton icon="fa fa-plus" value="Creer"
                                                         onclick="PF('creation').show()"/>

                                        /* Here is my dataTable */
                                        <p:dataTable id="tbl" value="#{antecedentMBean.listAllAntecedents()}" var="item"
                                                     emptyMessage="Aucun Antecedent trouvee" widgetVar="AntecedentTable"
                                                     paginator="true" paginatorTemplate="{CurrentPageReport} 
                                                     {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink}
                                                     {LastPageLink} {RowsPerPageDropdown} " paginatorPosition="top" rowsPerPageTemplate="5,10"
                                                     >


                                            <f:facet name="header">
                                                Liste des Patients
                                            </f:facet>

                                            <p:column>
                                                <f:facet name="header">
                                                    <h:outputText value="IdAntecedent"/>
                                                </f:facet>
                                                <h:outputText value="#{item.idAntecedent}"/>
                                            </p:column>
                                            <p:column>
                                                <f:facet name="header">
                                                    <h:outputText value="DateDiagnostic"/>
                                                </f:facet>
                                                <h:outputText value="#{item.dateDiagnostic}">
                                                    <f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss" />
                                                </h:outputText>
                                            </p:column>
                                            <p:column>
                                                <f:facet name="header">
                                                    <h:outputText value="DateGuerison"/>
                                                </f:facet>
                                                <h:outputText value="#{item.dateGuerison}">
                                                    <f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss" />
                                                </h:outputText>
                                            </p:column>
                                            <p:column>
                                                <f:facet name="header">
                                                    <h:outputText value="Allergies"/>
                                                </f:facet>
                                                <h:outputText value="#{item.allergies}"/>
                                            </p:column>
                                            <p:column>
                                                <f:facet name="header">
                                                    <h:outputText value="Therapie"/>
                                                </f:facet>
                                                <h:outputText value="#{item.therapie}"/>
                                            </p:column>
                                            <p:column>
                                                <f:facet name="header">
                                                    <h:outputText value="Diagnostique"/>
                                                </f:facet>
                                                <h:outputText value="#{item.diagnostique}"/>
                                            </p:column>


                                            <p:column headerText="Action" style="width:18%" exportable="false">
                                                <div class="ui-g">
                                                    <div class="ui-g-4">
                                                    /* Here are the buttons for editing*/
                                                        <p:commandButton icon="fa fa-pencil" update=":formulaire:repere" oncomplete="PF('modif').show()">
                                                            <f:setPropertyActionListener value="#{item}" target="#{antecedentMBean.antecedent}" />
                                                        </p:commandButton>
                                                    </div>
                                                    <div class="ui-g-4">
                                                    /* Here are the buttons for deleting*/
                                                        <p:commandButton icon="fa fa-trash" style="background-color: red" type="button" onclick="PF('cd').show()" />

                                                        <p:confirmDialog message="Voulez vous vraiment supprimer cet enregistrer?"
                                                                         header="Suppression en cours" severity="alert" 
                                                                         widgetVar="cd" global="true" showEffect="bounce" hideEffect="bounce">
                                                            <p:commandButton value="Oui" action="#{antecedentMBean.deleteAntecedent()}"
                                                                             oncomplete="PF('cd').hide()" icon="ui-icon-check">
                                                                <f:setPropertyActionListener target="#{antecedentMBean.antecedent}" value="#{item}"/>
                                                            </p:commandButton>
                                                            <p:commandButton value="Non" onclick="PF('cd').hide();" type="button" icon="ui-icon-close"/>
                                                        </p:confirmDialog>
                                                    </div>
                                                    <div class="ui-g-4">
                                                    /* Here are the buttons for displaying*/
                                                        <p:commandButton icon="fa fa-binoculars" update=":formulaire:view"     oncomplete="PF('voir').show()">
                                                            <f:setPropertyActionListener value="#{item}" target="#{antecedentMBean.antecedent}" />
                                                        </p:commandButton>
                                                    </div>
                                                </div>
                                            </p:column>

                                        </p:dataTable>

                                    </h:form>
                                </p:layoutUnit>
                            </p:layout>
                        </p:tab>
                    </p:tabView>
            </f:view>
        </ui:define>
    </ui:composition>
</h:body>

这是我的托管bean:     package managedbeans;

import entities.Operation;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.inject.Named;
import javax.faces.view.ViewScoped;
import sessions.OperationFacadeLocal;


Named(value = "operationMBean")
@ViewScoped
public class OperationMBean implements Serializable{

@EJB
private OperationFacadeLocal operationFacade;
private List<Operation> operationList;
private Operation operation;
private Date date = new Date();

public OperationFacadeLocal getOperationFacade() {
    return operationFacade;
}

public void setOperationFacade(OperationFacadeLocal operationFacade) {
    this.operationFacade = operationFacade;
}

public List<Operation> getOperationList() {
    return operationList;
}

public void setOperationList(List<Operation> operationList) {
    this.operationList = operationList;
}

public Operation getOperation() {
    return operation;
}

public void setOperation(Operation operation) {
    this.operation = operation;
}

public Date getDate() {
    return date;
}

public void setDate(Date date) {
    this.date = date;
}

 public List<Operation> createOperation(){
    operation.setDateCree(getDate());
    operation.setDateMaj(getDate());
    operationFacade.create(operation);
    operationList = operationFacade.findAll();
    return operationList;
}

public List<Operation> updateOperation(){
    operation.setDateMaj(getDate());
    operationFacade.edit(operation);
    operationList = operationFacade.findAll();
    return operationList;
}

public List<Operation> deleteOperation(){
    operationFacade.remove(operation);
    operationList = operationFacade.findAll();
    return operationList;
}


/**
 * Creates a new instance of OperationMBean
 */
public OperationMBean() {
}

}

我正在使用PrimeFaces 6.1 Netbeans 8.2 Glassfish 4.1 希望我的问题清楚 在此先感谢!!!

1 个答案:

答案 0 :(得分:0)

我通过在update属性中使用WidgetV而不是id解决了这个问题:

{{1}}

感谢Stackoverflow