2015-12-08 77 views
0

我有一个primefaces数据网格,我试图使用primefaces更新。我可以看到onMessage方法被调用,但是,只有在onMessage方法中设置了断点时,组件本身才会更新。这是处理程序:在原始浏览器中未收到推送事件

@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; 
    } 
} 

这是代码我呼吁更新我的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"/> 

和组件只是在的index.xhtml此刻底部:

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

我很难过,为什么这是,任何建议,将不胜感激。

+0

我假定您使用浏览器开发人员工具“调试”网络流量?检查'更新'属性值的正确性等? – Kukeltje

+0

@Kukeltje我会给它一个去,但我不知道我在找什么。 – zobbo

+0

是否执行了远程命令,它的响应看起来是什么样的(例如更新但是具有相同的数据),响应中的任何错误是称为etc的方法...... – Kukeltje

回答

0

我发现解决方案是将autoRun属性添加到我的remoteCommand标记中,这会在表单提交并重新加载页面后更新组件。

<p:remoteCommand name="updateWidgets" 
    actionListener="#{parliamentManager.findLatestPrices}" 
    update="resultDisplay" 
    autoRun="true"/> 
+0

奇怪的解决方案。那么你必须在某个地方有一个不同的问题,或者你没有发布的相关代码! – Kukeltje