2011-11-30 73 views
3

我在從<rich:calendar>中選擇日期時遇到了渲染data table的問題。我使用<a4j:ajax>進行渲染,但沒有任何效果。下面是代碼示例:Ajax渲染一個表格,它是在不同的表格中

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:rich="http://richfaces.org/rich" 
    xmlns:a4j="http://richfaces.org/a4j" 
    xmlns:composite="http://java.sun.com/jsf/composite"> 

    <rich:panel header="#{lang.reportPanelHeader}" id="panel" rendered="#{navigation.reportRendered}" width="700px" style="margin-left:250px"> 
     <a4j:status onstart="#{rich:component('statPane')}.show()" onstop="#{rich:component('statPane')}.hide()" /> 
     <h:form id="data_table_form"> 
      <rich:dataTable value="#{validateReportAction.reportList}" var="report" iterationStatusVar="it" id="data_table" rows="5"> 
       <rich:column> 
        <f:facet name="header">#</f:facet> 
        #{it.index + 1} 
       </rich:column> 

       <rich:column> 
        .... 
       </rich:column> 

       <f:facet name="footer"> 
        <rich:dataScroller page="#{validateReportAction.page}" /> 
       </f:facet> 
      </rich:dataTable> 
     </h:form> 

     <rich:popupPanel id="statPane" autosized="true" style="border: none; background-color: #e6e6e6;"> 
      .... 
     </rich:popupPanel> 

     <div id="bottom"> 
      <h:form id="calendarForm"> 
       <div id="left">     
        <div class="input" id="test_cal"> 
         <rich:calendar 
          dataModel="#{calendarModel}" 
          value="#{validateReportAction.selectedDate}" 
          boundaryDatesMode="scroll" 
          required="true" 
          requiredMessage="#{lang.dateRequiredMsg}" 
          mode="ajax" 
          id="date" 
          datePattern="dd.MM.yyyy" 
          popup="false"> 

          <a4j:ajax event="change" render="@all"/> 

         </rich:calendar> 

         <span class="error_msg"> 
          <rich:message for="date" ajaxRendered="true"/> 
         </span> 
        </div> 
       </div> 
      </h:form> 
     </div> 
    </rich:panel> 

</ui:composition> 

我被迫在<a4j:ajax event="change" render="@all"/>日曆使用@all,但我想僅渲染data table。我怎樣才能做到這一點?

+0

您的標記語法錯誤。開啓和關閉標籤不匹配。但是在查看頁面時,這已經拋出了Facelets異常。請小心準備片段中的問題:) – BalusC

+0

:>我會記住這一點,感謝:-)) – nyxz

回答

7

由於它位於不同的命名容器父項中,因此需要通過其絕對客戶端ID來引用它。要找到它,請在網頁瀏覽器中打開該頁面。 Rightclick and 查看源文件。找到由<rich:dataTable id="data_table">生成的HTML <table>元素。它會是這個樣子:

<table id="data_table_form:data_table"> 

你需要採取正是ID,與JSF命名容器分隔符(默認爲:),並用它在render屬性前綴。

<a4j:ajax event="change" render=":data_table_form:data_table" /> 
+0

真的很棒!我一直在努力解決這一整天:X – nyxz

+0

該解決方案的工作.......... thanx Balus –