My goal is to call a JSF managed bean method from inside a JS function.
This 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'}
);
};
My idea was having a hidden JSF ajax form, filling a hidden field and triggering click on submit commandlink:
<h:form id="hiddenFbForm">
<h:inputHidden id="hiddenFbToken" value="#{loginController.fbToken}" />
<h:commandLink id="hiddenFbLoginSubmit" actionListener="#{loginController.printFbInfo()}" />
</h:form>
However, this doesn't work. Page reloads, my printFbInfo server side method is never reached.
Do you have better ideas for calling a JSF server side bean from a JS function (programmatically, I don't want my user to click a button).
Another thing... I want the call to be AJAX, not reloading the page.
<h:commandLink id="hiddenFbLoginSubmit" action="#{loginController.printFbInfo}" />