Primefaces DefaultCommand按钮根据区域进行切换

Primefaces DefaultCommand按钮根据区域进行切换,primefaces,Primefaces,如您所见,我首先使用第一个commandButton查找一个人,然后在datatable中选择一个人,我有第二个commandButton,在选择一个人之后,我想在button2上切换defaultCommand,如何实现这一点 <h:form id="form" rendered="#{security.asRole('ADMIN') or security.asRole('GESTIONNAIRE')}"> <f:event type="pr

如您所见,我首先使用第一个commandButton查找一个人,然后在datatable中选择一个人,我有第二个commandButton,在选择一个人之后,我想在button2上切换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>



使用呈现属性生成两个默认命令。Rendered应该检查是否选择了person,并且调用的操作必须适合该人员。因为您每次都在更新整个表单,所以这应该是可行的

<p:defaultCommand target="boutonLigneAgent" rendered="#{personIsSelected()}"/>
<p:defaultCommand target="pgRechercheContrats" rendered="#{personIsNotSelected()}"/>

使用呈现属性生成两个默认命令。Rendered应该检查是否选择了person,并且调用的操作必须适合该人员。因为您每次都在更新整个表单,所以这应该是可行的

<p:defaultCommand target="boutonLigneAgent" rendered="#{personIsSelected()}"/>
<p:defaultCommand target="pgRechercheContrats" rendered="#{personIsNotSelected()}"/>


第二个按钮为onclick:onclick=“Regenerarcal();this.form.target=''blank''设置了特定事件,这就是我无法在viewBean中执行此操作的原因第二个按钮为onclick:onclick=“Regenerarcal();this.form.target=''blank''设置了特定事件,这就是我无法在viewBean中执行此操作的原因