【问题标题】:richfaces datatable and subtableRichfaces 数据表和子表
【发布时间】:2010-11-01 11:07:27
【问题描述】:

我有以下数据:

<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_&lt;id number&gt;不存在。

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

是否可以让rich:subTable 具有动态 id,我可以使用它来仅重新呈现该子表?

【问题讨论】:

    标签: jsf richfaces


    【解决方案1】:

    我现在使用的解决方法是:

    <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 设置复选框还会为每个对应的&lt;h:selectBooleanCheckbox value="#{row.checked}" /&gt; 设置 bean 中的值

    我不知道它会那样做。

    【讨论】:

      【解决方案2】:

      您可以尝试设置子表id="custTable" 并执行reRender="custTable" 看看是否适合您。

      【讨论】:

      猜你喜欢
      • 2011-05-30
      • 2012-08-16
      • 1970-01-01
      • 1970-01-01
      • 2011-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多