[英]Trigger JSF ajax form programmatically via JS
My goal is to call a JSF managed bean method from inside a JS function. 我的目标是从JS函数内部调用JSF托管bean方法。
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: 我的想法是拥有一个隐藏的JSF Ajax表单,填充一个隐藏的字段并触发对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.
页面重新加载,从未达到我的printFbInfo服务器端方法。
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). 您是否有从JS函数调用JSF服务器端bean的更好的主意(以编程方式,我不希望用户单击按钮)。
Another thing... I want the call to be AJAX, not reloading the page. 另一件事...我希望呼叫为AJAX,而不是重新加载页面。
Try Removing Braces from Action listener method 尝试从操作侦听器方法中删除括号
instead of #{loginController.printFbInfo()}
use #{loginController.printFbInfo}
. 代替
#{loginController.printFbInfo()}
使用#{loginController.printFbInfo}
。
Since you are using Primefaces you could use Primefaces RemoteCommand ( p:remoteCommand
) to achieve this. 由于您使用的是Primefaces,因此可以使用Primefaces RemoteCommand (
p:remoteCommand
)实现此目的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.