Primefaces DataTable、延迟加载和每行命令按钮 [英] Primefaces DataTable, lazy loading and CommandButton per row

查看:22
本文介绍了Primefaces DataTable、延迟加载和每行命令按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个简单的页面:

<h:form id="form">

    <p:dataTable value="#{testBean.unitTypeModel}" var="elem" lazy="true" rows="10">
        <p:column headerText="class">#{elem.class.simpleName}</p:column>
        <p:column headerText="code">#{elem.code}</p:column>
        <p:column headerText="description">#{elem.description}</p:column>
        <p:column headerText="action">
            <p:commandButton action="test2" icon="ui-icon ui-icon-wrench" value="edit">
                <f:setPropertyActionListener target="#{testBean.selection}" value="#{elem}"/>
            </p:commandButton>
        </p:column>
    </p:dataTable>

    <p:commandButton action="test2" icon="ui-icon ui-icon-wrench"/>

</h:form>

DataTable 中的 CommandButton 不起作用,只是刷新页面.但外面的那个正在工作.

and the CommandButton inside DataTable is not working, just refreshes page. but the one outside is working.

如果我这样改变valuelazy:

<h:form id="form">

    <p:dataTable value="#{testBean.unitTypeModel.load(0, 10, null, null, null)}" var="elem" lazy="false" rows="10">
        <p:column headerText="class">#{elem.class.simpleName}</p:column>
        <p:column headerText="code">#{elem.code}</p:column>
        <p:column headerText="description">#{elem.description}</p:column>
        <p:column headerText="action">
            <p:commandButton action="test2" icon="ui-icon ui-icon-wrench" value="edit">
                <f:setPropertyActionListener target="#{testBean.selection}" value="#{elem}"/>
            </p:commandButton>
        </p:column>
    </p:dataTable>

    <p:commandButton action="test2" icon="ui-icon ui-icon-wrench"/>

</h:form>

DataTable 中的 CommanButton 就像一个魅力.

the CommanButton inside DataTable works like a charm.

有人知道为什么吗?

这是一个错误吗?

我在

  • 玻璃鱼 3.1.2
  • JSF 2.1.11 (Mojarra)
  • PrimeFaces 3.4-快照

推荐答案

发现惰性数据模型必须是回发请求中的同一个实例,即使是具有完全相同值的新实例也不起作用.所以它必须至少由 @ViewScoped bean 提供.

found out that the lazy datamodel must be the same instance on postback request, even a new instance with the very same values will not work. so it must be provided from at least a @ViewScoped bean.

这篇关于Primefaces DataTable、延迟加载和每行命令按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆