Primeface的remoteCommand - 有一种方法可以执行一次吗?

时间:2014-06-01 14:25:26

标签: jsf primefaces remotecommand

Primefaces 3.5 JSF 2.1

我正在使用p:remoteCommand执行异步命令并在页面加载后更新我的视图,但看起来在每次迭代结束时它再次执行,等等......

这种行为是否正确?

如何只执行一次p:remoteCommand?

更新

我已经检查过我的remoteCommand是否在更新面板之外,所以谢谢你的回答,但它已经没问题了。我如何解决我的问题:

我不知道为什么但是使用来自Omnifaces(http://showcase.omnifaces.org/components/onloadScript)的onloadScript来调用remoteCommand函数它被多次调用,但使用$(document).ready ...只需一次。所以,我改变它并让它立即运作。

2 个答案:

答案 0 :(得分:4)

如果您最终处于类似行为的无限循环中,则可能会将父组件更新为<p:remoteCommand>

<h:form id="myform">
    <p:remoteCommand update="myform" actionListener="#{remoteCommandView.execute}" />
    ...
</h:form>

将它放在你想要更新的组件的外面/旁边,一切都应该没问题。

<h:form id="newform">
<p:remoteCommand update="myform" actionListener="#{remoteCommandView.execute}" />
</h:form>
<h:form id="myform">
...
</h:form>

答案 1 :(得分:4)

以单独的形式使用p:remoteCommand 使用process="@this"partialSubmit="true",只是为了更加安全。