【问题标题】:p:remoteCommand not executing / not called from javascriptp:remoteCommand 未执行/未从 javascript 调用
【发布时间】:2021-03-16 19:56:49
【问题描述】:

通过点击注销调用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);
}

我尝试通过动作侦听器更改动作,但没有成功。

【问题讨论】:

    标签: jsf primefaces remotecommand


    【解决方案1】:

    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 代码,结果是:

    值是:::::::::::::::::::::一些文本

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-08
      • 1970-01-01
      • 2017-02-13
      • 1970-01-01
      相关资源
      最近更新 更多