使用ajax primefaces渲染panelgrid

时间:2012-09-04 11:59:22

标签: java java-ee jsf-2 primefaces rendering

我有这个

<p:selectOneMenu  id="dec" value="#{editCommandController.myCom.decision}" >  
                        <f:selectItems value="#{editCommandController.decisions}" />  
                        <p:ajax update="etat :myform:alors" event="change" />
                    </p:selectOneMenu>  

允许禁用此

<p:selectOneMenu  id="etat" value="#{editCommandController.myCom.etat}" disabled="#{editCommandController.myCom.decision eq 'rejettée'}" >  
                        <f:selectItems value="#{editCommandController.etats}" />   
                    </p:selectOneMenu> 

检查条件时 我还想在检查相同条件时隐藏此panelgrid:

 <h:panelGrid id="alors"   rendered="#{editCommandController.myCom.decision ne 'rejettée'}" >
                    <p:dataTable id="cars" style="width: 80px;" var="car" value="#{editCommandController.pdm}" paginator="true" rows="10"  
                                 selection="#{editCommandController.selectedPapier}" selectionMode="single" >  

                        <p:ajax event="rowSelect" listener="#{editCommandController.onRowSelect()}"   
                                update=":myform:jesuis" />  

                        <f:facet name="header">  
                            RadioButton Based Selection  
                        </f:facet>                    

                        <p:column headerText="libelle">  
                            #{car.libelle}  
                        </p:column>  

                        <p:column headerText="format">  
                            #{car.format}  
                        </p:column>  

                        <p:column headerText="stock" >  
                            #{car.stock}  
                        </p:column>  

                    </p:dataTable>  


                    <h:outputText  id="jesuis" value=" c est la papier : #{editCommandController.selectedPapier.libelle}"  />


                    <h:panelGrid columns="2" cellpadding="5" style="margin-top: 22px;">  
                        <h:outputLabel value="Reliure :" for="city" />
                        <p:selectOneMenu id="city" value="#{addPapierController.choixReliure}">  
                            <f:selectItem itemLabel="choisir reliure" itemValue="" />  
                            <f:selectItems value="#{addPapierController.libelleReliures}" />  
                            <p:ajax 
                                listener="#{addPapierController.handleCityChange}" />  
                        </p:selectOneMenu>
                    </h:panelGrid>

                </h:panelGrid>

但我注意到,当第一次加载页面时,它会检查panelgrid的panelgrid

你是否有任何想法一直在使用这个功能,如上面的selectonemenu,谢谢

1 个答案:

答案 0 :(得分:5)

使用p:outputPanel围绕panelGrid。然后,在“dec”selectOneMenu中,还更新outputPanel。假设所有这些组件都在同一个表单中,它将如下所示:

<p:selectOneMenu  id="dec" value="#{editCommandController.myCom.decision}" >  
       <f:selectItems value="#{editCommandController.decisions}" />  
       <p:ajax update="etat gridContainer :myform:alors" event="change" />
</p:selectOneMenu>  

<p:outputPanel id="gridContainer" layout="block" >
    <h:panelGrid id="alors" rendered="#{editCommandController.myCom.decision ne 'rejettée'}" >
         <!-- panel grid contents here.. -->  
    </h:panelGrid>
</p:outputPanel>