简体   繁体   中英

Execute onevent with values changed by listener

I have this code

<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>

When I click on the minus, the listener of the ajax tag should be executed before the onevent . Normally, it's the other way round.

I tried this:

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");
        }
    }
 }

Now, the listener method will be executed before my JavaScript function but in #{organizercontroller.deletePossible} , I change the value of canDelete and this value isn't correct when I read it.

How can I fix this?

UPDATE:

Using status === 'success' didn't work either.

I cannot seem to find a link/post of adding callback parameters in an ajax call without using PrimeFaces or OmniFaces Ajax

But you can always do something like updating a part of the page that contains a javascript function which you update in the ajax call and contains/returns the EL

<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>

and call that function in your ajax response handler

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM