Primeface´s remoteCommand - there is a way to execute once?

16.8k Views Asked by At

Primefaces 3.5 JSF 2.1

I´m using p:remoteCommand to execute async commands and update my view after page loading but looks that in the ends of each iteration it execute again and so on...

Is this behaviour correct?

How to execute only once the p:remoteCommand?

update

I have checked that my remoteCommand was out of the update panel, so thank you for the answers but it was already OK. How I solve my problem:

I dont know why but using the onloadScript from Omnifaces (http://showcase.omnifaces.org/components/onloadScript) to call the remoteCommand function it is called many times, but using $(document).ready ... just once. So, I change it and got it working right now.

2

There are 2 best solutions below

2
On BEST ANSWER

If you end up in an infinite loop like behaviour, you are likely updating a parent component to your <p:remoteCommand>.

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

Put it outside/next to the component you wish to update and things should be fine.

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

Use p:remoteCommand in separate form.
Use process="@this" and partialSubmit="true", just to be on safer side.