【问题标题】:Primefaces update table from another formPrimefaces 从另一种形式更新表
【发布时间】:2014-10-01 16:22:10
【问题描述】:

我想从另一个刷新我的惰性表。我有以下 xhtml:

<h:form id="tableform">
    <p:remoteCommand name="updateTable" update="table" />

    <p:dataTable widgetVar="tableWidget" id="table"
        selection="#{personBean.selectedPerson}" selectionMode="single"
        lazy="true" paginator="true" var="person" rowKey="#{person.id}"
        value="#{personBean.personModel}" paginatorPosition="bottom" rows="5"
        paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}">            

        <p:column filterBy="#{person.name}" headerText="Names:"
            sortBy="#{person.name}">
            <h:outputText value="#{person.name}" />
        </p:column>


    </p:dataTable>

    <p:commandButton value="buttonInForm2" update=":tableform" />
    <p:commandButton value="buttonInForm" update="@form" />
</h:form>

<h:form>
    <p:commandButton value="directUpdate" update=":tableform" />
    <p:commandButton value="directUpdate" update=":tableform:table" />
    <p:commandButton value="remoteCommand" oncomplete="updateTable()" />
</h:form>

remoteCommand(我当前的解决方案)和 from 中的按钮刷新表格。但是当我使用“directUpdate”按钮时,表格的过滤文本消失了。但我不明白为什么? (过滤值停留在背景但文字为空)

我知道我可以在 table 上使用 widgetVar.filter() 但分页器将被重置。我的解决方案是 remoteCommand,它一切正常,表格重新加载当前页面和过滤器。 (欢迎提供更好的解决方案)

这个问题为什么reset直接更新文本而不更新表单呢?

感谢您的时间。

【问题讨论】:

    标签: jsf primefaces datatable updatemodel


    【解决方案1】:

    &lt;p:dataTable&gt; 有自己的隐藏输入,用于分页、选择和过滤,以便服务器端知道客户端状态。这样它就可以准备和返回与客户端相同的状态。

    如果您提交某个表单,则只会发送特定表单中包含的输入,而不会发送其他表单。这不是 JSF 特定的问题。 HTML 一直都是这样工作的。否则,万维网看起来会大不相同。

    通过从表单外部调用&lt;p:remoteCommand&gt;,您基本上提交了“正确”的表单,即包含它的表单也包含数据表。

    请注意,您本身不需要&lt;p:commandButton&gt;,只需一个简单的&lt;p:button ... onclick="updateTable(); return false;"&gt; 就足够了。即使是整个第二种形式也不需要这项工作。

    【讨论】:

    • 感谢隐藏输入的解释。是的,第二种形式只在我的大例子中,但你是对的,我不需要它。谢谢你:)
    猜你喜欢
    • 1970-01-01
    • 2016-03-07
    • 2012-12-23
    • 1970-01-01
    • 2010-10-06
    • 2011-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多