JQuery,JSF和a4j:commandLink

时间:2009-11-28 13:12:58

标签: jquery-ui jsf richfaces ajax4jsf jquery-dialog

我在JSF中使用jQuery Dialog和Ajax提交时遇到问题。 我有以下用于显示对话框窗口的代码:

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

现在,在显示对话框后,A4j.AJAX.Submit(..)是 执行,无论如何,我可以,例如,通过整体 A4J.AJAX.Submit(...)到“对话框”并从“ok”选项执行它? 当且仅当用户单击“确定”时,我才需要执行提交。 谢谢你的帮助 JQ

1 个答案:

答案 0 :(得分:4)

您可以定义:

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

并在OK功能中调用它,如:

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