2012-06-01 72 views
1

我有一個基於dataTable的動態表單,嵌套在另一個dataTable內。重新呈現單個數據錶行

上選擇從嵌套dataTable一排,我想用<p:ajax>

<h:form id="form"> 

    <h:dataTable var="field" value="#{testBean.propertyList}" varStatus="status"> 

     <h:column> 
      <h:outputLabel value="#{field.label}"/> 
     </h:column> 

     <h:column> 
      <h:panelGrid columns="2" styleClass="app-grid" rendered="#{field.toOne}"> 
       <h:panelGroup id="value"> 
        <h:outputText value="#{testBean.entity[field.name]}"/> 
       </h:panelGroup> 

       <h:panelGroup> 
        <p:commandButton id="button" type="button" icon="ui-icon ui-icon-search"/> 
        <p:overlayPanel for="button" my="left bottom" at="left bottom" widgetVar="panel_#{field.name}"> 
         <p:dataTable 
          id="table" 
          value="#{field.selectableModel}" 
          selection="#{testBean.entity[field.name]}" 
          selectionMode="single" 
          var="item" 
          rows="10" 
          paginator="true" 
          paginatorAlwaysVisible="true" 
          paginatorPosition="bottom" 
          paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" 
          currentPageReportTemplate="{totalRecords} records found" 
          rowsPerPageTemplate="5,10,15"> 

          <p:ajax event="rowSelect" update=":???:value" oncomplete="panel_#{field.name}.hide()"/> 
          <p:column headerText="entity">#{item}</p:column> 
         </p:dataTable> 
        </p:overlayPanel> 
       </h:panelGroup> 
      </h:panelGrid> 
     </h:column> 

    </h:dataTable> 

</h:form> 

問題更新從父dataTable相應的行生成組件樹不會有反覆明確的子組件dataTable

<HtmlForm enctype="application/x-www-form-urlencoded" id="form" inView="true" prependId="true" rendered="true" submitted="false" transient="false"> 
    <HtmlDataTable border="-2147483648" first="0" id="j_idt101" inView="true" rendered="true" rowIndex="-1" rowStatePreserved="false" rows="0" transient="false" var="field"> 
     <UIColumn id="j_idt103" inView="true" rendered="true" transient="false"> 
      <HtmlOutputLabel escape="true" id="j_idt120" inView="true" rendered="true" style="" transient="false"/> 
     </UIColumn> 
     <UIColumn id="j_idt121" inView="true" rendered="true" transient="false"> 
      <HtmlPanelGrid border="-2147483648" columns="2" id="j_idt122" inView="true" rendered="false" styleClass="app-grid" transient="false"> 
       <HtmlPanelGroup id="value" inView="true" rendered="true" transient="false"> 
        <HtmlOutputText escape="true" id="j_idt227" inView="true" rendered="true" transient="false"/> 
       </HtmlPanelGroup> 
       <HtmlPanelGroup id="j_idt117" inView="true" rendered="true" transient="false"> 
        <CommandButton ajax="true" async="false" disabled="false" escape="true" global="true" icon="ui-icon ui-icon-search" iconPos="left" id="button" immediate="false" inView="true" inline="false" partialSubmit="true" readonly="false" rendered="true" transient="false" type="button"/> 
        <OverlayPanel appendToBody="false" at="left bottom" dynamic="false" for="button" id="j_idt228" inView="true" my="left bottom" rendered="true" transient="false" widgetVar="panel_"> 
         <DataTable currentPageReportTemplate="{totalRecords} records found" draggableColumns="false" editable="false" emptyMessage="No records found." filterEvent="keyup" first="0" id="table" inView="true" lazy="false" liveScroll="false" pageLinks="10" paginator="true" paginatorAlwaysVisible="true" paginatorPosition="bottom" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rendered="true" resizableColumns="false" rowIndex="-1" rowStatePreserved="false" rows="10" rowsPerPageTemplate="5,10,15" scrollHeight="-2147483648" scrollRows="0" scrollWidth="-2147483648" scrollable="false" selectionMode="single" sortOrder="ascending" transient="false" var="item"> 
          <Column colspan="1" disabledSelection="false" filterBy="false" filterMatchMode="startsWith" filterMaxLength="2147483647" filterPosition="bottom" headerText="entity" id="j_idt229" inView="true" rendered="true" resizable="true" rowspan="1" transient="false" width="-1"> 
           #{item} 
          </Column> 
         </DataTable> 
        </OverlayPanel> 
       </HtmlPanelGroup> 
      </HtmlPanelGrid> 
     </UIColumn> 
    </HtmlDataTable> 
</HtmlForm> 

因此,我正在考慮使用<c:forEach>而不是父母dataTable使每一行e在組件樹中xplicit。

但第一個問題是testBean@ViewScoped ...

和第二個是使用<c:forEach>導致Java Heap Space錯誤...

一些暗示?

+0

它不通過性能原因創建每行的子組件。相反,狀態是在內部處理的,但是如果您擁有正確的clientId,JSF將以正確的狀態檢索組件。訣竅是從父組件獲取客戶端ID,但記住dataTable是NamingContainer,所以您需要從父節點中查找ID(使用':'作爲前綴,不記得確切) – lu4242

回答

1

給外表一個固定的id

<h:dataTable id="table" ...> 

然後你就可以使用

<p:ajax ... update=":form:table:value" /> 
+0

我不敢相信它是這麼容易... –

+0

不客氣。 – BalusC