【问题标题】:Row rendering on extendedDataTable doesnt work扩展 DataTable 上的行渲染不起作用
【发布时间】:2013-11-28 14:33:35
【问题描述】:

问题(简​​短版)

我对 Richfaces(4.3.2-final)有疑问。
我正在尝试在 Rich:extendedDataTable 中重新渲染行/单元格。我无法让它工作。 唯一有效的方法是重新渲染整个表格。

我能找到的所有示例/教程都是针对 3.3 版的。这些解决方案对我不起作用。

我希望您能帮助我提供解决方案或 4.2+ 示例/教程。


问题的长版本

未选中行单元格:

<a4j:outputPanel layout="block" rendered="#{inactive}">
    <h:outputText 
       value="#{cc.attrs.rowItem.getValue(cc.attrs.id)}"
       styleClass="outputField"
       style="#{cc.attrs.style}">
     </h:outputText>
</a4j:outputPanel>

选定的行单元格:

<a4j:outputPanel layout="block" rendered="#{active and field.echoed}">
<h:inputText
    value="#{field.value}" 
    id="#{cc.attrs.id}ID"
    disabled="#{field.disabled}"
    readonly="#{field.readonly}"
    rendered="true"
    title="#{field.title}"/>
    ....
</a4j:outputPanel>

在选择其他行时:

<a4j:ajax event="selectionchange" 
          listener="#{crudBean.actionForm.selectionListener}" 
      render="messages,saveButton,deleteButton,multiOccurenceTable"
/>

HTML 代码,未选中行单元格:

<td class="rf-edt-td-j_idt230">
  <div class="rf-edt-c rf-edt-c-j_idt230">
    <div class="rf-edt-c-cnt">
      <div id="multiOccurenceTable:0:soort:soort">
        <div id="multiOccurenceTable:0:soort:j_idt140">
          <span class=" outputField" style="">VO</span>
        </div>
      </div>
    </div>
  </div>
</td>

选定的行单元格 HTML:

<td class="rf-edt-td-j_idt230">
  <div class="rf-edt-c rf-edt-c-j_idt230">
     <div class="rf-edt-c-cnt">
       <div id="multiOccurenceTable:1:soort:soort">
         <div id="multiOccurenceTable:1:soort:j_idt240">
           <input id="multiOccurenceTable:1:soort:soortID" name="multiOccurenceTable:1:soort:soortID" value="VO" type="text">
         </div>
       </div>
     </div>
  </div>
</td>

我的尝试: 现在将 on selectionchange 重新渲染放在表上:“multiOccurenceTable”。 这有效,在每次选择更改时,整个表都会重新呈现。

为了提高性能,我尝试在行或单元格级别更新表格。我无法让这个工作。我尝试了简单和更复杂的解决方案,都没有奏效。我究竟做错了什么? (大多数示例/教程都是针对互联网上的 Richfaces 3.3 的,这可能是一个原因)

尝试 1,手动更新行/单元格:

所有 3 行:当我按下“保存”按钮时没有任何反应

<a4j:commandLink actionListener="#{crudBean.actionForm.save}"
     render="multiOccurenceTable:0,multiOccurenceTable:1,multiOccurenceTable:2"
     reRender="multiOccurenceTable:0,multiOccurenceTable:1,multiOccurenceTable:2">Save
</a4j:commandLink>

一个单元格:当我按下“save1”按钮时什么也没发生

<a4j:commandLink actionListener="#{crudBean.actionForm.save}"
     render="multiOccurenceTable:@rows(crudBean.actionForm.rowsToUpdate):soort"
     reRender="multiOccurenceTable:@rows(crudBean.actionForm.rowsToUpdate):soort">Save1
</a4j:commandLink>

根据tutorial rich 3.xexample (rich 3.3),我也尝试使用 ajaxKeys 没有成功

如果您有任何可能的解决方案,请告诉我。


我的错误已修复。错误不是渲染。但是渲染的条件是在被渲染的组件之外设置的。这导致重新渲染未更新值的组件,从而导致屏幕上没有任何变化。

经验教训:如果您有渲染条件,请确保条件值在重新渲染的组件内。


【问题讨论】:

    标签: jsf-2 datatable richfaces row


    【解决方案1】:

    我对richfaces 4 不够熟悉,无法了解extendedDatatable 的详细信息。快速搜索让我相信,不可能自动渲染一行,因为一行不是组件。

    所以您似乎不得不渲染单个单元格。

    渲染工作基于组件的 clientId。您可以在您的 html 代码中找到确切的 ID。因为它适用于那些clientId,所以您要渲染的组件已经需要渲染。

    换句话说,你需要用一个面板包装你的组件,该面板有一个 id 并且默认呈现:

    <h:outputPanel layout="block" id="soortPanel">
        <h:outputText 
           value="#{cc.attrs.rowItem.getValue(cc.attrs.id)}"
           rendered="#{inactive}">
        </h:outputText>
        <h:inputText
           value="#{field.value}" 
           rendered="#{active}"/>
    </h:outputPanel>
    

    输出面板应该得到一个类似的 id:multiOccurenceTable:1:soortPanel,你应该能够渲染那个 id。

    【讨论】:

    • 附注您需要使用术语渲染。 reRender 是来自早期版本 a4j 的 a4j 术语。 JSF 2 基本标准化了 a4j 并将 reRender 重命名为 render。我认为 reRender 术语更好,因为您无法渲染尚未渲染的任何内容。 Primefaces 对此有最好的说法。 “更新”,但这并不能真正帮助消除混乱:)
    • 谢谢。错误在其他地方,这个答案让我朝着正确的方向前进。
    • ps。为将来的读者更正: 应该是 .
    猜你喜欢
    • 1970-01-01
    • 2011-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-31
    • 2015-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多