Primefaces RemoteCommand time lag when calling bean

3.9k views Asked by At

I have performance problem with RemoteCommand caling bean method time lag.

Using primefaces 4.0, our xhtml page, at runtime loads significant amount of divs into panel

<p:outputPanel id="runtime_panel" autoUpdate="true" />

Some SelectOneRadio controls have listeners through setOnchange() method. They call RemoteCommand, which is defined in xhtml page at design time:

<p:remoteCommand name="ourRemoteCommand" 
actionListener="#{bean.someMethod}" update="runtime_panel"
/>

The purpose of bean.someMethod is to show or hide certain GUI controls in our page through ajax. Bean is request scoped.

The problem is, there passed certain time lag, when calling bean.someMethod from client. In my tests, javascript responses suddenly, but there is reasonably long lag passeed when I catch bean.someMethod through breakpoint on server side - about 2.5 seconds.

I also change bean scope to session scoped to eliminate construction phase lag, but this seams not problem - it didnt solve time lag.

If there are only small amount of elements in "runtime_panel", i didn't notice any lag, and breakpoint stops immediately in "bean.someMethod". There is corelation between number of controls and response time.

I also create another test - put dummy RemoteCommand at the beginning of the page at own form.

<form>
<p:remoteCommand name="rcgg" partialSubmit="true" process="@this" update="@none" actionListener="#{bean.testMethod()}" />
<h:outputText id="msgs" value="Ajax Submit" />
<p:commandButton type="button" onclick="console.log('client start');rcgg('ddd');console.log('client end')" value="Ajax1" icon="ui-icon-refresh" />
</form> 

So, server side code executes immediately too. But when "outputPanel" has many gui elements, there is also time lag when server side starts to execute, even there is not any relation to this RemoteCommand "rcgg". Strange.

I also tested with several RemoteCommand arributes (

immediate="false" async="true" partialSubmit="true" ignoreAutoUpdate="true" process="@none" global="false"  
 update="@none"

) but without success too.

I dont have any idea how to get rid of this "bean calling lag".
I really need your help.

2

There are 2 answers

0
Kishor Prakash On

Usually you have to use process=@this on p:remoteCommand or else it will submit the entire h:form and its components.
So its better to keep the p:remoteCommand in separate h:form.

If this also doesn't work you can always use the RequestContext's update method on ManagedBean to update the component.

RequestContext.getCurrentInstance().update("COMPONENT_ID_TO_UPDATE")
0
ℛɑƒæĿᴿᴹᴿ On

This trick speeds up starting load content of your page using remoteCommand.


Example of Primefaces RemoteCommand:

<p:remoteCommand name="load_users"
                 process="@this"
                 update="@form"
                 actionListener="#{myBean.loadUsers}" />

The name attribute of the p:remoteCommand is a bodyless JavaScript code that initiates the entire process. The actionListener through a call to myBean.loadUsers of the backing bean, load data and causes a partial update in the form (@form) or the attribute ID of your target component.

The JavaScript snippet below is a common sight in many jQuery codes. It is a handler for the jQuery ready event. It calls our load_users() JavaScript function, setted as name attribute of remoteCommand, when the page is ready for more manipulation. At this point the page has started to render and has already become visible to the user. You will need to included this in the begin section of the page.

<script type="text/javascript">
    $(document).ready(function() {
        load_users(); 
    });            
</script>

Reference: