0

beforeunload保存されていないデータが含まれている場合にメッセージを表示するフォームを含む Facelet ページがあります。そのために、次の JavaScript を使用しています。

$(window).on('beforeunload', function(){
    var val = document.getElementById("saveFormId:newInputId").value;
    var flagVal = (val=='true');
    if(flagVal)
        return 'Are you sure you want to leave?';
});

同じページに、ロケールを変更する別のフォームがあります。

<h:form id="localeForm">
    <p:selectOneButton value="#{localeBean.selectedLocale}"
        valueChangeListener="#{localeBean.countryLocaleCodeChanged}"
        onchange="submit()" style="height:1px;margin-top:7px;"
        styleClass="ui-language-button">
        <f:selectItems value="#{localeBean.languages}" />
    </p:selectOneButton>
</h:form>

ただし、これはbeforeunloadハンドラーもトリガーします。beforeunloadハンドラーで上記のフォームの送信を無視したいと思います。どうすればこれを達成できますか?

4

1 に答える 1

0

onchange="submit()"ページ全体を送信して、onbeforeunloadイベントをトリガーします。アクションを実行するには ajax を使用する必要があります。

<p:selectOneButton value="#{localeBean.selectedLocale}" style="height:1px;margin-top:7px;"        styleClass="ui-language-button">
    <f:selectItems value="#{localeBean.languages}" />
    <p:ajax event="change" listener="#{localeBean.countryLocaleCodeChanged}" />  
</p:selectOneButton>

現在の実装によっては、countryLocaleCodeChanged0 引数または のインスタンスのいずれかを受け入れるように変更する必要がある場合があります。AjaxBehaviorEvent

于 2013-08-15T06:26:46.077 に答える