Using Primefaces JavaScript to invoke the JSF method on a bean on the server

The Primefaces User Guide provides examples of how to make AJAX calls on the server.

PrimeFaces.ajax.AjaxRequest('/myapp/createUser.jsf',
{
    formId: 'userForm',
    oncomplete: function(xhr, status) {alert('Done');}
});

I cannot figure out how to call a specific method. My goal is to terminate the session from the client using JavaScript.

+5
source share
3 answers

RemoteCommand is a good way to achieve this because it provides you with a JavaScript function that performs this function (calling bean, updating, submitting the form, etc., everything the command can do).

From PrimeFaces 3.4 Documentation :

<p:remoteCommand name="increment" actionListener="#{counter.increment}"
out="count" />

<script type="text/javascript">
function customFunction() {
    //your custom code
    increment(); //makes a remote call
}
</script>
+16
source

p: commandLink, Javascript click().

<p:commandLink id="hiddenLink" 
   actionListener="#{bean.methodToInvoke}" style="display:none"/>

$('#hiddenLink').click();
+4

@PostConstruct bean, requsted JSF EL, #{bean}.

@ManagedBean
@RequestScoped
public class Bean {

    @PostConstruct
    public void init() {
        // Here.
    }

}

, , - ? JSF/PrimeFaces <f:ajax> <p:ajax> .

Window unload beforeunload? , , . , . . , .

+1

All Articles