通过单击logout调用javascript函数后,不会执行p:remotecommand。
这是我的XHTML代码:
<script type="text/javascript">
function logoutAccount() {
debugger;
var txt = "eeeeeeeeeeeeeee";
command([{name:'param',value:txt}]); //This is important
}
</script>
<a href="#" onclick="logoutAccount()"><i class="fa fa-sign-out fa-fw"></i> Logout</a>
<p:remoteCommand name="command" action="#{MyiaTaskBean.method}" />这是我在Java bean中的代码:
public void method() {
String value = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("param");
System.out.print("value is::::::::::::::::::::::"+value);
}我试图通过动作监听器来改变动作,但它不起作用。
发布于 2020-12-16 23:05:03
p:remoteCommand需要在表单内部。
下面的代码在我的环境中工作(你还没有说你使用的是哪个JSF/PF版本):
<script>
function logoutAccount() {
console.log('logoutAccount fired!');
var txt = 'some text';
command([{name:'param',value:txt}]);
}
</script>
<a href="#" onclick="logoutAccount()"><i class="fa fa-sign-out fa-fw"></i> Logout</a>
<h:form>
<p:remoteCommand name="command" action="#{testBean.method}" />
</h:form>使用您的java代码,结果是:
文本值为:
https://stackoverflow.com/questions/65149059
复制相似问题