【问题标题】:How Can i Update a Table (not datatable) with a Primefaces CommandButton如何使用 Primefaces CommandButton 更新表(不是数据表)
【发布时间】:2014-12-10 11:58:09
【问题描述】:
<h:form id="tableForm">
   <table id="myTable">
     <tr>
       <th>HeaderOne</th>  
       <th>HeaderTwo</th>
       <th>HeaderThree</th>
     </tr>
     <ui:repeat value="#{myBean.List}" var="row">
       <tr class="myRows">
         <td><input type="text" value="#{row.fieldOne} required="required" /></td>
         <td><input type="text" value="#{row.fieldTwo}  /></td>
         <td><input type="text" value="#{row.fieldThree} /></td>
       </tr>
     </ui:repeat>
   </table>
   <p:commandButton id="myButton" value="Load" action="#{myBean.load}" process="@this" update="myTable" />
</h:form>

我想从我的 bean 中将一些东西加载到我的 inputFields 中,但是当我按下保存时有一个字段是必需的。所以我必须将进程设置为@this。

之后我希望更新我的表格。但我不工作。

我做错了什么?

【问题讨论】:

    标签: html jsf primefaces


    【解决方案1】:

    尝试更新表单

    <p:commandButton ... action="#{myBean.load}" process="@this" update="tableForm" />
    

    由于表格不是 jsf 元素而是“纯”html,所以不能在 jsf 元素中使用它的 id

    【讨论】:

      【解决方案2】:

      Schäbo 的回答是正确的 (+1),但 Primefaces 还提供了一个 p:fragment 组件,因此您可以只更新您想要的区域:

      <p:fragment id="myFragmentReloaded">
        <table>
          ...
        </table>
      </p:fragment>
      

      然后

      <p:commandButton ... action="#{myBean.load}" process="@this" update="myFragmentReloaded" />
      

      【讨论】:

      • 太棒了。不知道fragment
      猜你喜欢
      • 1970-01-01
      • 2016-01-16
      • 2015-03-26
      • 1970-01-01
      • 2015-01-14
      • 2015-03-04
      • 2017-08-17
      • 2014-06-11
      • 2012-12-03
      相关资源
      最近更新 更多