2016-11-23 163 views
0

正如你可以看到我第一次找到一個人與第一個commandButton,然後我選擇一個人在數據表中,我有第二個commandButton,我想切換defaultCommand on button2我選擇了一個人後,我怎麼能做到這一點?Primefaces DefaultCommand按鈕根據區域切換

<h:form id="form" 
     rendered="#{security.asRole('ADMIN') or security.asRole('GESTIONNAIRE')}"> 
     <f:event type="preRenderView" listener="#{paieAgentView.init()}" /> 

     <p:fieldset legend="Recherche de l'agent"> 
      <p:panelGrid columns="2"> 
       <p:panelGrid columns="2" id="pgRechercheAgent"> 
        <h:outputLabel value="Matricule :" /> 
        <p:inputText id="matricule" 
         value="#{paieAgentView.agentSearched.matricule}"> 
         <p:ajax process="matricule" partialSubmit="true" event="keyup" /> 


        <h:commandButton id="boutonLigneAgent" 
         action="#{paieAgentView.searchLigneAgent()}" 
         value="Rechercher les agents" icon="ui-icon-search" 
         update="listAgents" immediate="true" > 
         <f:ajax render="@form" execute="@this" /> 
        </h:commandButton> 


        <br /> 
       </p:panelGrid> 

       <p:dataTable id="listAgents" var="agt" 
        value="#{paieAgentView.listLigneAgent}" 
        selection="#{paieAgentView.agentSelected}" 
        rowKey="#{agt.matricule}" style="margin-bottom:0" 
        selectionMode="single" scrollRows="20" scrollable="true" 
        liveScroll="true" scrollHeight="250"> 

        <p:ajax event="rowSelect" update=":form:pgRechercheContrats" /> 

        <p:column headerText="Matricule"> 
         <h:outputText value="#{agt.matricule}" /> 
        </p:column> 
        <p:column headerText="Nom"> 
         <h:outputText value="#{agt.nomPat} #{agt.prenom}" /> 
        </p:column> 

       </p:dataTable> 

      </p:panelGrid> 

      <p:defaultCommand target="boutonLigneAgent" /> 
     </p:fieldset> 
     <p:fieldset legend="Critères de recherche"> 
      <p:panelGrid columns="3" id="pgRechercheContrats"> 

       <h:panelGrid columns="1" style="margin-bottom:10px" cellpadding="5"> 
        <p:outputLabel for="typePeriode" value="Période de paie:" /> 
        <p:selectOneRadio id="typePeriode" 
         value="#{paieAgentView.typePeriode}"> 
         <f:selectItem itemLabel="Période de paie" itemValue="paie" /> 
         <f:selectItem itemLabel="Période d'origine" itemValue="origine" /> 
        </p:selectOneRadio> 
       </h:panelGrid> 


       <h:panelGrid columns="2" id="pgCalendar"> 
        <h:outputLabel value="Date Debut : " for="calendrierDateDebut" /> 
        <p:calendar id="calendrierDateDebut" 
         value="#{paieAgentView.dateDebut}" pattern="yyyy-MM-dd" 
         effect="slideDown" navigator="true" mode="inline" 
         locale="#{sessionControleur.langue}" style="moisAnSeul" /> 
        <h:outputLabel value="Date fin : " 
         for="calendrierDateFin" /> 
        <p:calendar id="calendrierDateFin" 
         value="#{paieAgentView.dateFin}" pattern="yyyy-MM-dd" 
         effect="slideDown" navigator="true" mode="inline" lang="fr" 
         locale="fr" style="moisAnSeul" /> 
       </h:panelGrid> 


       <p:selectManyCheckbox id="gridTypesPaie" 
        value="#{paieAgentView.selectedTypesPaie}" columns="1" 
        layout="pageDirection"> 
        <f:selectItems value="#{paieAgentView.typesPaie}" var="type" 
         itemLabel="#{type.label}" itemValue="#{type.value}" /> 
       </p:selectManyCheckbox> 

      </p:panelGrid> 
     </p:fieldset> 

     <p:commandButton process="pgRechercheContrats" 
      icon="ui-icon-file-pdf" value="Editer les fiches de paie" 
      action="#{paieAgentView.printPaieAgent()}" update="@form" 
      escape="false" ajax="false" 
      onclick="regenererCal();this.form.target='_blank'" /> 

    </h:form> 

回答

0

使2個defaultCommands具有呈現屬性。渲染應該檢查是否被選中,並且所調用的動作必須適當。因爲要更新整個窗體每次都會有一些變化這應該工作

​​
+0

第二個按鈕具有的onclick特定事件: 的onclick =「regenererCal(); this.form.target =‘_空白’」 這就是爲什麼我不能在viewBean中做到這一點 – coshikipix