I have a primefaces datagrid that I'm trying to update using primefaces Push. I can see that the onMessage method is called, however the component itself only updates if I have set a breakpoint in the onMessage method. This is the handler:
@PushEndpoint("/prices")
public class PricesResource {
private static final Logger logger = Logger.getLogger("PricesResource");
@OnMessage(encoders = {JSONEncoder.class})
public OrderBook onMessage(OrderBook orderBook) throws InterruptedException {
logger.log(Level.INFO, "PricesResource.onMessage price {0}", orderBook.getPrice());
return orderBook;
}
}
This is the code I call to update the component in my index.xhtml:
<p:socket onMessage="handleMessage" channel="/prices" />
<script type="text/javascript">
function handleMessage(data)
{
updateWidgets();
}
</script>
<p:remoteCommand name="updateWidgets"
actionListener="#{parliamentManager.findLatestPrices}"
update="resultDisplay"/>
And the component is just at the bottom of index.xhtml at the moment:
<h:panelGroup id="resultDisplay">
<p:dataGrid id="prices" var="orderBooks" value="#{parliamentManager.latestPricesResults}" columns="3" rows="12">
<p:column>
<p:panel header="#{orderBooks.bidOrderId.member.memberId}">
<h:panelGrid columns="1">
<h:outputText value="#{orderBooks.price}" />
</h:panelGrid>
</p:panel>
</p:column>
</p:dataGrid>
</h:panelGroup>
I'm pretty stumped as to why that is, any suggestions would be appreciated.
I found the solution was to add the autoRun attribute to my remoteCommand tag, this updates the component after the form has been submitted and the page reloads.
<p:remoteCommand name="updateWidgets"
actionListener="#{parliamentManager.findLatestPrices}"
update="resultDisplay"
autoRun="true"/>