2010-11-01 31 views
1

我有以下确定年代:RichFaces的数据表和子表

<rich:dataTable id="grid1" value="#{monitorForm.customerList}" var="custRow"> 
<rich:column width="5"> 
    <h:selectBooleanCheckbox value="#{custRow.selected}"> 
    <a:support event="onclick" action="#{monitorForm.selectOrderLines(custRow)}" 
     reRender="custTable_#{custRow.id}"/> 
    </h:selectBooleanCheckbox> 
</rich:column> 

<rich:subTable id="custTable_#{custRow.id}" 
     var="row" value="#{custRow.orderList}" rendered="#{custRow.show}"> 
<rich:column width="5"> 
<h:selectBooleanCheckbox value="#{row.checked}" /> 
</rich:column> 

    <rich:column> 
<h:outputText value="#{row.name}" /> 
</rich:column> 
</rich:subTable> 

</rich:dataTable> 

当我点击复选框动作#{monitorForm.selectOrderLines(custRow)} 设置所选客户的复选框,我只想要子表为客户进行重新描绘。 以上不起作用。

错误是[AjaxContext] Target component for id custTable_<id number>不存在。

当我使用reRender="grid1" 时,一切正常,但有很多行时可能会非常缓慢。

是否有可能让rich:subTable带有一个动态ID,我可以用它来重新生成只有该子表?

回答

0

我现在使用一种解决方法是:

<rich:dataTable id="grid1" value="#{monitorForm.customerList}"> 
    <rich:column width="5"> 
    <h:selectBooleanCheckbox value="" onclick="selectAllPackingLists(this, '#{custRow.id}')"/> 
    </rich:column> 

<rich:subTable var="row" value="#{custRow.orderList}" rendered="#{custRow.show}"> 
    <rich:column> 
     <input type='hidden' value='#{custRow.id}'/> 
    </rich:column> 

<rich:column width="5"> 
<h:selectBooleanCheckbox value="#{row.checked}" /> 
</rich:column> 

</rich:subTable> 

</rich:dataTable> 

javascript函数:

   function selectAllPackingLists(o, id) { 
        var elem = jQuery("table[id='monitorFrm:grid1'] > tbody"); 
        var checked = o.checked; 

        var rows = elem.attr('rows'); 

        jQuery.each(rows, function(index, row) { 
          // for each row check if the input value in 1st column 
          // matches the selected customer id 
         var td = jQuery('td:first', this); 
         var hiddenFld = jQuery('input:first', td); 

         if (hiddenFld.val() == id) { 
            // set the checkbox in the 2nd column to true 
          var td2 = jQuery('td:nth-child(2)', this); 
          var cb = jQuery('input:first', td2); 

          jQuery(cb).attr('checked', checked); 
         } 
        }); 
       } 

什么是伟大,是因为设置通过JQuery的复选框还设置Bean中值分别对应<h:selectBooleanCheckbox value="#{row.checked}" />

我不知道它会这么做。

0

你可以尝试设置子表id="custTable"和做reRender="custTable",看看是否适合你。

+0

嗨,可以有很多subTables取决于客户数量,所以1个ID都不起作用。另外我读了这个ID不能动态设置。有关于此的一个很好的答案在http://stackoverflow.com/questions/316790/dynamic-ids-in-jsf-seam – Guus 2010-11-08 13:07:13