This is my simple test, when soclet in 2.xhtml receives an event from the server, it will fire a click event in commandbutton, and this command (you can make it invisible) will update the desired target: Bean:
@ManagedBean(name = "globalCounter")
@SessionScoped
public class GlobalCounterBean implements Serializable {
private static final long serialVersionUID = 1L;
private int count;
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public void increment() {
count++;
PushContext pushContext = PushContextFactory.getDefault().getPushContext();
pushContext.push("/counter", String.valueOf(count));
}
}
1.xhtml:
<h:body>
<h:form id="form">
<h:outputText id="out" value="#{globalCounter.count}" styleClass="ui-widget display" />
</h:form>
<p:socket onMessage="handleMessage" channel="/counter" />
</h:body>
2.xhtml:
<h:form id="form">
<h:outputText id="out" value="#{globalCounter.count}" styleClass="ui-widget display" />
<br />
<p:commandButton onclick="alert('test')" id="btn" process="@form" value="Click" update="@parent" />
</h:form>
<p:socket onMessage="handleMessage" channel="/counter" />
<script type="text/javascript">
function handleMessage(data) {
$('#form\\:btn').click();
}
</script>
source
share