【问题标题】:Execute onevent with values changed by listener使用监听器更改的值执行 onevent
【发布时间】:2015-06-05 07:21:25
【问题描述】:

我有这个代码

<h:commandLink>
    <f:ajax execute="@this"
            render=":organizerTable :organizerData :delete @form" 
            onevent="deleteOrganizer"
            listener="#{organizercontroller.deletePossible}"/>

    <span id="minus" class="add-on glyphicon glyphicon-minus" aria-hidden="true"></span>  
</h:commandLink>

当我点击减号时,ajax标签的监听器应该在onevent之前执行。通常情况下,情况正好相反。

我试过这个:

function deleteOrganizer(data) {
    var status = data.status;
    if (status === 'complete') {
        if (#{organizercontroller.canDelete}) {
             alert("Value: " + #{organizercontroller.canDelete});
             window.location.href = "#id_delete_popup";
            }
        else {
            alert("false");
        }
    }
 }

现在,侦听器方法将在我的 JavaScript 函数之前执行,但在 #{organizercontroller.deletePossible} 中,我更改了 canDelete 的值,当我读取它时这个值不正确。

我该如何解决这个问题?

更新:

使用status === 'success' 也不起作用。

【问题讨论】:

    标签: javascript ajax jsf


    【解决方案1】:

    如果不使用 PrimeFaces 或 OmniFaces Ajax,我似乎找不到在 ajax 调用中添加回调参数的链接/帖子

    但您始终可以执行一些操作,例如更新包含您在 ajax 调用中更新并包含/返回 EL 的 javascript 函数的页面部分

    <h:commandLink>
        <f:ajax execute="@this"
                render=":organizerTable :organizerData :delete @form myCallback" 
                onevent="deleteOrganizer"
                listener="#{organizercontroller.deletePossible}"/>
    
        <span id="minus" class="add-on glyphicon glyphicon-minus" aria-hidden="true"></span>  
    </h:commandLink>
    <ui:fragment id="myCallback">
        function myFunction() {
            return #{organizercontroller.deletePossible}
        }
    </ui:fragment>
    

    并在您的 ajax 响应处理程序中调用该函数

    function deleteOrganizer(data) {
        var status = data.status;
        if (status === 'complete') {
            if (myFunction()) {
                 alert("Value: " + myFunction());
                 window.location.href = "#id_delete_popup";
                }
            else {
                alert("false");
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多