JQuery, JSF and a4j:commandLink

强颜欢笑 提交于 2019-12-08 01:01:56

问题


I have a problem with using jQuery Dialog and Ajax submit in JSF. I have the following code for displaying Dialog windows:

                <script type="text/javascript"> 
                        jQuery(function(){ 
                                // Dialog 
                                jQuery('#dialog').dialog({ 
                                        dialogClass: 'alert', 
                                        autoOpen: false, 
                                        width: 300, 
                                        height: 150, 
                                        modal: true, 
                                        resizable: false, 
                                        overlay: { 
                                                backgroundColor: '#000', 
                                                opacity: 0.5 
                                        }, 
                                        buttons: { 
                                                "Ok":  function() { 
                                                        jQuery(this).dialog("close"); 
                                                        return true; 
                                                }, 
                                                "Cancel": function() { 
                                                        jQuery(this).dialog("close"); 
                                                        return false; 
                                                } 
                                        } 
                                }); 

                                // Dialog Link 
                                jQuery('#dialog_link').click(function(){ 
                                        jQuery('#dialog').dialog('open'); 
                                        return false; 
                                }) 
                                .hover( 
                                        function() { jQuery(this).addClass('ui-hover-state'); }, 
                                        function() { jQuery(this).removeClass('ui-hover-state'); } 
                                ); 

                        }); 
                </script> 
It works as it should - it displays box when link is clicked. 
Now, I have something like this, for deleting something: 
<a4j:commandLink 
        actionListener="#some.action" 
        reRender="something" 
        onclick="if(!jQuery('#dialog').dialog('open')){return false}" 

ok, this commandLink is rendered as follows: 
<a href="#" 
        id="some:long:id:j_id338" 
        name="formName:something:j_id338" 
        onclick="if(!jQuery('#dialog').dialog('open')){return 
false};A4J.AJAX.Submit('something:something'); 
        return false;" 
>drop</a> 

now, after displaying the dialog box, the A4j.AJAX.Submit(..) is executed, is there anyway, that I can for example, pass the whole A4J.AJAX.Submit(...) to "dialog" and execute it from "ok" option? I simply need to execute submit if and only if user clicks OK. Thank you for help JQ


回答1:


You can define:

<a4j:jsFunction name="okClicked"
    actionListener="#{some.action}" 
    reRender="something" />

And call it in the OK function, like:

"Ok": function() { 
    jQuery(this).dialog("close");
    okClicked();
    return true; 
}


来源:https://stackoverflow.com/questions/1812500/jquery-jsf-and-a4jcommandlink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!