更新动态选项卡中的dataTable

时间:2014-05-17 10:41:33

标签: jsf-2 primefaces datatable tabview

我的目标是创建我称之为 tabPrincipal 的按需标签。在我的tabPrincipal中,我不同于其他标签。目前,我在tabPrincipal中有一个标签,我称之为 tabGeneral 。在tabGeneral中,我是一个动态添加行的dataTable。这就是我的问题开始的地方。当我点击"添加新行"我在dataTable中看不到更多行。但是,在列表中创建了一个新对象(Ecriture)(List mesEcritures)。消息来源会更清楚:

名为menu.xhtml

<h:form id="formMenu">
    <p:tieredMenu autoDisplay="false">
        <p:submenu label="Demande DEC"  >
            <p:menuitem value="Faire une demande" actionListener="#{demandeCtrl.newDemande}" update=":formPrincipalTabViewDEC:principalTabViewDEC"/>
        </p:submenu>
    </p:tieredMenu>
</h:form>

page.xhtml

<h:form id="formPrincipalTabViewDEC">
        <p:tabView id="principalTabViewDEC" var="demande" 
            value="#{demandeCtrl.sessionDataCtrl.tabDemande}" 
            style="border: none" cache="false" >
            <p:ajax event="tabClose" listener="#{demandeCtrl.onDecClose}" />
            <p:tab id="demandeTab" title="DEC: #{demande.id}" closable="true" >
                <p:tabView id="tabviewDEC" >
                    <p:tab id="tabGeneral" title="Général">
                        <h:panelGrid columns="1">
                            <h:panelGrid columns="1">
                                <p:outputLabel title="Description" for="descriptionDEC" value="Description:" style="margin-bottom: 10px"></p:outputLabel>
                                <p:inputText id="descriptionDEC" value="#{demande.description}" 
                                    label="DescriptionDEC" maxlength="100" size="100" >
                                    <f:validateLength maximum="100" />
                                </p:inputText>
                                <p:message for="descriptionDEC" />
                            </h:panelGrid>
                        </h:panelGrid>
                        <h:panelGrid columns="1">
                            <h:panelGrid columns="3">
                                <h:panelGrid columns="1" >
                                    <p:outputLabel value="Nom du demandeur"/>
                                    <p:inputText id="demandeurDEC" size="35"  value="#{demande.demandeur}" readonly="true"/>
                                </h:panelGrid>  
                                <h:panelGrid columns="1" >
                                    <p:outputLabel value="Identifiant"/>
                                    <p:inputText id="identifiantDEC" value="#{demande.id}" readonly="true"/>
                                </h:panelGrid>
                                <h:panelGrid columns="1">
                                    <p:outputLabel value="Etat"/>
                                    <p:inputText id="etatDEC"  value="#{demande.etat}" readonly="true"/>
                                </h:panelGrid>
                            </h:panelGrid>
                        </h:panelGrid>

                        <p:dataTable id="dataTableSaisiePiece" var="line" 
                            value="#{demande.ecritureDataModel}"
                            editable="true" editMode="cell"  
                            selection="#{demandeCtrl.selected}" >
                            <p:column selectionMode="single" style="width:1%"/>
                            <p:column headerText="Numéro" style="width:10%"  rendered="true" >
                                <p:cellEditor>
                                    <f:facet name="output">
                                        <p:outputLabel  id="labelNumero" 
                                            value="#{line.numero}">
                                        </p:outputLabel>
                                    </f:facet>
                                    <f:facet name="input">
                                        <p:inputText id="inputNumero"  style="width:92%"
                                            value="#{line.numero}" >
                                        </p:inputText>
                                    </f:facet>
                                </p:cellEditor>
                            </p:column> 
                        </p:dataTable>
                        <p:commandButton  actionListener="#{demandeCtrl.doNewLine(demande)}"
                            value="Add new row" update=":formPrincipalTabViewDEC:principalTabViewDEC:tabviewDEC:tabGeneral" 
                             icon="ui-icon-plusthick" process="@this">

                        </p:commandButton>
                    </p:tab>

                </p:tabView>
            </p:tab>
        </p:tabView>
    </h:form>

ManagedBean demandeCtrl

@ManagedBean
@RequestScoped
public class demandeCtrl{

    @ManagedProperty("#{sessionDataCtrl}")
    private SessionDataCtrl sessionDataCtrl;

    @ManagedProperty("#{ecritureCtrl}")
    private EcritureCtrl ecritureCtrl;

    public void newDemande(){
        Demande uneDemande = new Demande();
        uneDemande.setDemandeur(sessionDataCtrl.getUser().getUsername());
        sessionDataCtrl.getTabDemande().add(demandeBean.getId(uneDemande));
    }

    public void doNewLine(Demande demande) { 
        ecritureCtrl.newEcritureLine(demande.getMesEcritures());
    }

    ...

}

ManagedBean SessionDataCtrl

@ManagedBean
@SessionScoped
public class SessionDataCtrl {

    private List<Demande> tabDemande;
    public SessionDataCtrl() {
        tabDemande = new ArrayList<Demande>();
    }

    ...

}

ManagedBean EcritureCtrl

@ManagedBean
@RequestScoped
public class EcritureCtrl implements Serializable {
    public void newEcritureLine(List<Ecriture> mesEcritures) {
        Ecriture uneEcriture = new Ecriture();
        uneEcriture.setNumeroLigne(mesEcritures.size()+1);
        mesEcritures.add(uneEcriture);
    }

    ...

}

有人可以帮我解决这个问题吗?

提前谢谢

0 个答案:

没有答案