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.
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>
p: commandLink, Javascript click().
<p:commandLink id="hiddenLink" actionListener="#{bean.methodToInvoke}" style="display:none"/>
$('#hiddenLink').click();
@PostConstruct bean, requsted JSF EL, #{bean}.
@PostConstruct
#{bean}
@ManagedBean @RequestScoped public class Bean { @PostConstruct public void init() { // Here. } }
, , - ? JSF/PrimeFaces <f:ajax> <p:ajax> .
<f:ajax>
<p:ajax>
Window unload beforeunload? , , . , . . , .
unload
beforeunload