How to open Modal pop up in JSF 2 using JQuery

前端 未结 1 2023
猫巷女王i
猫巷女王i 2020-11-30 13:10

I have a requirement that in my JSF page there will be a commandButton, and on clicking that commandButton it will fire a action method which will perform some logic and bas

1条回答
  •  忘掉有多难
    2020-11-30 13:41

    Here's a complete working example

    I used display:none to hide the h:panelGroup dialog container cause the .dialog function will make it visible when its needed to be

    You also can hide the real jsf command buttons and access it through dialog button with jquery # selector and invoke the .click on it like I did in the js file.

    One last thing , used onclick="initDialog(); return false;" to call the dialog js function and added return false so the commandbutton wont try to navigate away...

    By using the jQuery UI Dialog you will get maximum flexibility/control over your dialogs.

    The example consists from 2 file (one .xhtml and one .js) ,

    I used jQuery and jQueryUI , no need in any other plugins at all

    index.xhtml

    
    
    
    
        
            
            
            
            
        
        
            
            
                   
            
    
        
    
    
    

    and scripts.js

    function initDialog() {
     $("#idOfDialogPlaceHolder").dialog({
         modal: true,
         buttons: {
                SomeButton: function () {
                    $("#justAButton").click();
                },
                Close: function () {
                    $(this).dialog("close");
                }
         },
     });
    }
    

    That's it

    0 讨论(0)
提交回复
热议问题