Counter example won't work with ajax

UI Components for JSF
Post Reply
peterremec
Posts: 21
Joined: 16 Jan 2015, 15:50

06 Jun 2016, 09:54

I've had problems using PF Push (PF 5.3) on WebSphere Portal 7, so I tried push using PF 4. I used counter example from docs for testing purposes.

web.xml

Code: Select all

<servlet>
		<servlet-name>Push Servlet</servlet-name>
		<servlet-class>org.primefaces.push.PushServlet</servlet-class>
</servlet>

<servlet-mapping>
		<servlet-name>Push Servlet</servlet-name>
		<url-pattern>/primepush/*</url-pattern>
</servlet-mapping>
bean (application scope):

Code: Select all

private int count;

public void setCount(int count) {
	this.count = count;
}

public int getCount() {
	return count;
}

public synchronized void increment() {
		count++;
		PushContext pushContext = PushContextFactory.getDefault().getPushContext();
		pushContext.push("/counter", String.valueOf(count));
}
First I tried to update counter with JS code and it worked:

Code: Select all

<h:form>
	<h:outputText id="counter" value="#{bean.count}" styleClass="display" />
	<p:commandButton value="Click" actionListener="#{bean.increment}" />
</h:form>

<p:socket channel="/counter" onMessage="handleMessage" />

<script type="text/javascript">
	         function handleMessage(data) {
	             $('.display').html(data); 
            }
</script>
Example above works fine, but if I try to use ajax to update counter:

Code: Select all

<p:socket channel="/counter" >
	<p:ajax event="message" update="@(.display)" />
</p:socket>
counter is not updated. There's no error/exception in portal (WAS 8) console, looks OK in Chrome, too. Only Firefox and IE display error messages, but I'm not sure what they mean.

Chrome console:
Image

Firefox console:
Image

IE console:
Image

In FF console, when I click on 'counter:2:1' link, pushed data is displayed, like:

Code: Select all

12|{"data":"4"}
Is this even the right response format?
PrimeFaces 11 | WebSphere Application Server 9.0.5.6 | MyFaces 2.0.17

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 22 guests