7

我有这个简单的页面:

<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>

内部不工作,只是刷新页面CommandButtonDataTable但是外面的那个正在工作。

如果我改变这种方式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>

内部就像一个魅力CommanButtonDataTable

有人知道为什么吗?

这是一个错误吗?

我上线了

  • 玻璃鱼 3.1.2
  • JSF 2.1.11 (莫哈拉)
  • PrimeFaces 3.4-快照
4

2 回答 2

7

发现延迟数据模型在回发请求中必须是相同的实例,即使具有相同值的新实例也不起作用。所以它必须至少由一个@ViewScopedbean 提供。

于 2012-08-17T09:55:07.400 回答
4

自发布此问题以来已经过去了四年,但问题仍然存在于 PrimeFaces 6.0 中。

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

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

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

<p:remoteCommand name="remoteCall" action="#{bean.doStuff()}">
</p:remoteCommand>

现在,我们所要做的就是从 DataTable 中调用这个 RemoteCommand。我正在使用一个链接来执行 javascript 调用,但你可以使用一个按钮或任何你喜欢的东西:

<p:column>
    <p:link value="#{item.id}" href="#" onclick="remoteCall([{name:'id', value:#{item.id}}])">
    </p:link>
</p:column>

此链接提供了一种调用 javascript 函数“remoteCall”的方法,该函数将对“bean.doStuff()”执行 ajax 调用。

请注意,onClick 事件不仅包含对“remoteCall”的 javascript 调用,还包含一个只有一个参数的参数数组,名为“id”,值为“#{item.id}”。这将允许 RemoteCommand 向支持 bean 发送一个名为“id”的参数。

在“doStuff”方法中,您必须检索“id”参数值:

public void doStuff () {

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

}
于 2017-03-05T11:24:39.430 回答