0

ボタンをクリックすると開くモーダル ダイアログがあり、開くと.xhtmlpage が読み込まれます。

この XHTML ページ内には、親ウィンドウ (ダイアログが初期化される場所) にデータを戻すためのボタンがあり、その後、ダイアログを閉じたいのですが、閉じません!! これは私のコードです:

先頭ページ:

<script type="text/javascript">                         
    var selected_row_data_json;

    window.lang = new jquery_lang_js();

    $().ready(function () {
        $.ajaxSetup ({
            // Disable caching of AJAX responses
            cache: false
        });
        createDataListDialog();                
    });     

    function setSelectedRowJsonData(row_data_)
    {  
       selected_row_data_json = row_data_;                           
    }           

    function setFormSelectedValues()
    {
        $('#dataListDialog').dialog('close');  
    }

    function createDataListDialog()
    {
        $("#dataListDialog").dialog(
        {                   
            autoOpen: false,                      
            modal: true,                    
            resizable: true,
            open: function (event, ui) {   
            /* <![CDATA[ */                    
                $('#dataListDialog').css('overflow', 'hidden');

                $('body').css('overflow','hidden');
                $(this).load("data_list.xhtml");                       
            /* ]]> */
            },
            height: 400,
            width: 550,
            close: function (event, ui) {                        
                $(this).dialog('destroy');
                createDataListDialog();                        
            },
            create: function(event, ui)   
            {                                                  
                $(this).parents(".ui-dialog").css("padding", 0);                           
                $(this).parents(".ui-dialog:first")
                    .find(".ui-dialog-content").css("padding", 0);
            }
        });       
    }
</script>

<f:view>
    <h:outputLabel value="Code:"  lang="en" onclick="openDialog('dataListDialog');return false;" />

    <div id="dataListDialog" lang="en" title="Users" dir="#{user.dir}">                
    </div>
</f:view>

data_list.xhtmlページ:

<script type="text/javascript">
    function test()
    {
        window.parent.setSelectedRowJsonData(selected_row_data_json);
        window.parent.setFormSelectedValues();
    }
</script> 

<h:form id="dataListForm" ">   
    <input type="button" onclick="test()" value="TEST">/input>
</h:form> 

私は何か間違ったことをしていますか?何か足りない?読み込まれたページからダイアログが閉じられないのはなぜですか?

更新: ロードされたページがページである場合、htmlそれはうまく機能します - ダイアログは閉じています。問題は、ページがxhtmlページの場合です..どうすればこれを修正できますか?

どんな助けでも大歓迎です!

4

1 に答える 1

0

An easier way of doing this would be firing off the test() function after the load completes successfully -- that is, bind it to the complete event:

$(this).load("data_list.xhtml",
    complete: function(response, status, xhr) {
        window.parent.setSelectedRowJsonData(selected_row_data_json);
        window.parent.setFormSelectedValues();
    });   

Bonus: add some conditionals that handle server errors using the status object.

于 2012-12-06T16:11:49.393 に答える