Ajax Framework - RemoteCommand

RemoteCommand provides a simple way to execute backing bean methods with javascript.

Sometimes you need to add a dynamic callback for when the remote command completes. Each remote command, when called, returns a promise-like object you can use for that purposes. Try opening a dev console and run the function "runRemoteCommand". See below for the code.

Documentation
<h:form>
    <p:remoteCommand name="rc" update="msgs" action="#{remoteCommandView.execute}" />

    <p:remoteCommand name="rc2" update="msgs" action="#{remoteCommandView.execute}"
        oncomplete="alert('Return value from server: ' + args.serverTime)"/>
    
    <p:growl id="msgs" showDetail="true" skipDetailIfEqualsSummary="true" />

    <h:panelGrid columnClasses="value">
        <p:commandButton type="button" value="Execute simple command" icon="pi pi-refresh"
            onclick="rc()" />

        <p:commandButton type="button" value="Passing parameters to bean method" icon="pi pi-refresh"
            onclick="rc([{name: 'param1', value: 'foo'}, {name: 'param2', value: 'bar'}])" />

        <p:commandButton type="button" value="Receiving values form the bean" icon="pi pi-refresh"
            onclick="rc2()" />                
    </h:panelGrid>

    <script type="text/javascript">
        function runRemoteCommand(param1, param2) {
            var promise = rc([{name: 'param1', value: param1}, {name: 'param2', value: param2}]);
            promise.then(function(responseData) {
                var serverTime = responseData.jqXHR.pfArgs.serverTime;
                console.log("Request successful, returned server time is", serverTime);
            }).catch(function(error){
                console.error("Request failed", error);
            });
        }
    </script>
</h:form>

FREE THEMES

Built-in component themes created by the PrimeFaces Theme Designer.

nova-light Nova-Light
nova-dark Nova-Dark
nova-colored Nova-Colored
luna-blue Luna-Blue
luna-amber Luna-Amber
luna-green Luna-Green
luna-pink Luna-Pink
omega Omega

PREMIUM TEMPLATES

Create awesome applications in no time using the premium templates and impress your users.