Disable/enable commandbutton on ajax event

后端 未结 2 1457
生来不讨喜
生来不讨喜 2021-02-10 20:30

I want to be able to disable the commandbutton below once it\'s hit and enable it once the event listener runs and msg1 is rendered.



        
2条回答
  •  故里飘歌
    2021-02-10 21:22

    You could do it with help of the onevent attribute of which points to a JavaScript function which handles the JSF Ajax events.

    E.g.:

    
      
    
    

    (note that I fixed the wrong EL in listener as well)

    with this JS:

    function handleDisableButton(data) {
        var buttonElement = data.source; // The HTML DOM element which invoked the ajax event.
        var ajaxStatus = data.status; // Can be "begin", "complete" and "success".
    
        switch (ajaxStatus) {
            case "begin": // This is called right before ajax request is been sent.
                buttonElement.disabled = true;
                break;
    
            case "complete": // This is called right after ajax response is received.
                // We don't want to enable it yet here, right?
                break;
    
            case "success": // This is called when ajax response is successfully processed.
                buttonElement.disabled = false;
                break;
        }
    }
    

提交回复
热议问题