My aim is to execute a JSF managed bean method from within a JavaScript function.
Here is the function:
var fbLogin = function() {
FB.login(
function(response) {
if (response.authResponse) {
var access_token = FB.getAuthResponse()['accessToken'];
console.log(access_token);
//document.getElementById("hiddenFbForm:hiddenFbToken").value = access_token;
//document.getElementById("hiddenFbForm:hiddenFbLoginSubmit").onclick();
} else {
console.log("ERROR");
}
},
{scope:'email'}
);
};
I had the idea of using a hidden JSF ajax form, populating a hidden field and then clicking on submit commandlink:
<h:form id="hiddenFbForm">
<h:inputHidden id="hiddenFbToken" value="#{loginController.fbToken}" />
<h:commandLink id="hiddenFbLoginSubmit" actionListener="#{loginController.printFbInfo()}" />
</h:form>
Unfortunately, this approach does not seem to work. The page reloads, and my printFbInfo server-side method is never triggered.
Do you have any better suggestions for invoking a JSF server-side bean from a JavaScript function programmatically without requiring user interaction?
Also, I prefer the call to be AJAX-based without causing a page refresh.