1

JSF 2.1 と Primefaces に基づくアプリケーションがあります。Jquery を使用して ajax リクエストを作成し、ページのステータスを更新する必要があります。ここにコード:

    <?xml version="1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <f:view>
        <h:head>
        </h:head>
        <h:body>
            <h:outputText id="counterViewer" value="#{dataController.outputMessage}"
                          styleClass="counter-viewer" />
            <h:form id="dataForm" >
                <h:outputScript>
                    jQuery(document).ready(function() {
                        jQuery(document).on("count", function(event, count) {
                            alert( "Count: " + count );
                            document.getElementById("#{view.getClientId(facesContext)}:counterViewer").innerText = count;   
                            var hiddenCountValue = document.getElementById("#{view.getClientId(facesContext)}:dataForm:hiddenCountValue");
                            hiddenCountValue.value = count;
                            jsf.ajax.request(hiddenCountValue, 'change');
                        });
                     });
                </h:outputScript>
                <h:inputHidden id="hiddenCountValue" value="#{dataController.outputMessage}"/>
            </h:form>
        </h:body>
    </f:view>
</html>

Chrome を使用するとすべて正常に動作しますが、firefox 22 では jsf.ajax.request(hiddenCountValue, 'change'); 機能しません。

コードを Firefox でも実行するために使用できる他の関数はありますか? jsf.ajax.request(hiddenCountValue, 'change'); を実行しない理由 Firefoxで動作しますか?

ありがとう

ルカフ:見る>

Chrome を使用すると問題なく動作しますが、Firefox では

jsf.ajax.request(hiddenCountValue, '変更');

機能が動作していないようです。

コードの互換性を高めるために使用できる他の関数はありますか? どうして

jsf.ajax.request(hiddenCountValue, '変更');

Firefoxで動作しませんか?

ありがとう

ルカ

4

1 に答える 1

1

また、Chromeでもまったく機能しないはずです。それはおそらく誤解によって引き起こされます。おそらくリクエストは実際に送信されますが、それでもサーバー側では何の役にも立たないでしょう。<f:ajax>つまり、<h:inputHidden>をデコードするものがありませんjsf.ajax.request()

この不器用なハック/回避策の試みを捨ててください。すでに PrimeFaces を使用しているので、その<p:remoteCommand>(ショーケースの例はこちら) を取得してください。

<h:form>
    <p:remoteCommand name="sendCount" process="@this" action="#{bean.processCount}" />
</h:form>
<h:outputScript target="body">
    $(document).on("count", function(event, count) {
        $(".counter-viewer").text(count);
        sendCount([{ name: "count", value: count }]);
     });
</h:outputScript>

public void processCount() {
    String count = FacesContext.getCurrentInstance().getRequestParameterMap().get("count");
    // ...
}

実際にどのように機能するかを知るjsf.ajax.requestには、次の関連する質問と回答に進んでください。

于 2013-07-25T13:15:55.857 に答える