1

I have an application based on JSF 2.1 and Primefaces. I need to make an ajax request using Jquery and update the page status. Here the code:

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

When I use Chrome everything works fine but on firefox 22 the jsf.ajax.request(hiddenCountValue, 'change'); function doesn't work.

Are there other functions that I can use to run my code also on Firefox? Why doesn't jsf.ajax.request(hiddenCountValue, 'change'); work on firefox?

Thanks

Lucaf:view>

When I use Chrome everithyngs work fine but on firefox the

jsf.ajax.request(hiddenCountValue, 'change');

function seems not work.

Are there other functions that I can use to make my code more compatible? Why

jsf.ajax.request(hiddenCountValue, 'change');

not work on firefox?

Thanks

Luca

user993487
  • 21
  • 3

1 Answers1

1

It should also not have worked in Chrome at all. It's likely caused by a misinterpretation. Perhaps the request is actually sent, but even then, it wouldn't do anything useful in the server side. You namely don't have any <f:ajax> on the <h:inputHidden> which would decode the jsf.ajax.request().

Throw away this clumsy hack/workaround attempt. As you're already using PrimeFaces, just grab its <p:remoteCommand> (showcase example here).

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

with

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

To learn how jsf.ajax.request really works, head to the following related questions & answers:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555