Jsf 2 Primefaces数据表、延迟加载和每行CommandButton

Jsf 2 Primefaces数据表、延迟加载和每行CommandButton,jsf-2,primefaces,lazy-loading,datatables,Jsf 2,Primefaces,Lazy Loading,Datatables,我有一个简单的页面: <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

我有一个简单的页面:

<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
内部的
CommanButton
就像一个符咒

有人知道为什么

是虫子吗

我在

  • 玻璃鱼3.1.2
  • JSF2.1.11(莫哈拉)
  • PrimeFaces 3.4-SNAPSHOT

发现延迟数据模型必须是回发请求中的同一实例,即使是具有相同值的新实例也无法工作。因此,它必须至少由一个
@ViewScoped
bean提供。

这个问题发布至今已经四年了,但问题仍然存在于6.0版本中

我将为那些不想(或不能)使用ViewScoped bean的人发布一个解决方案

前提是:“不能将任何“ajaxified”项放在绑定到RequestScoped stuff的惰性数据表中”。从未。请记住,抛出ajax调用的任何东西都不会起作用

因此,第一步是在datatable之外进行ajax调用。我们将使用RemoteComand执行此操作。您可以将此RemoteCommand放置在DataTable之外的任何位置(当然是在表单内部)


这并非完全正确:如果通过使用
@ViewScoped
在会话中找到相同的
@LazyDataModel
实例,这会很有帮助,但您也可以使用
@RequestScoped
。关键是当在
APPLY\u REQUEST\u VALUES
中对方法
isrowavable()
求值时,该方法必须返回true,并且字段
pageSize
必须包含大于零的值。我通过扩展
LazyDataModel
并重载两个方法来实现这一点:
isRowAvailable()
,在这里我调用
load(…)
,并将结果应用于
setwrappedata()
和第二个方法
setRowIndex(introwIndex)
,其中我将
页面大小设置为默认值
<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>
<p:remoteCommand name="remoteCall" action="#{bean.doStuff()}">
</p:remoteCommand>
<p:column>
    <p:link value="#{item.id}" href="#" onclick="remoteCall([{name:'id', value:#{item.id}}])">
    </p:link>
</p:column>
public void doStuff () {

    String id = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id");

}