【问题标题】:How can i refresh dataTable with push in primeFaces如何通过推送 primeFaces 来刷新 dataTable
【发布时间】:2013-04-07 11:34:21
【问题描述】:

我需要知道如何在 index2.xhtml 中的数据更改时更新 index1.xhtml 中的 DataTable
使用 push...我在 index1.xhtml 中定义套接字,如下所示:

<p:socket channel="/table" onMessage="handle"/>

在 bean 中:

public void contract(){
 ....
PushContext pcont=PushContextFactory.getDefault().getPushContext();
pcont.push("/table",something);
}

我不知道的是如何在 javaScript 中更新 dataTable:

<script type="text/javascript">
  function handle() {
          ???
        }
</script>

【问题讨论】:

  • 我使用remoteCommand但有一些错误...我如何在没有其他参数的情况下使用pcont.push("/table")。我认为这会导致错误
  • 什么是触发器?例如:
  • @RongNK yes.that's a ...primeFaces/push 中的样本毫无意义
  • 你的问题是这样的吗:stackoverflow.com/questions/15903816/…
  • 如果你不关心性能,我想你可以,你有没有尝试一些解决方案?

标签: java jsf-2 primefaces


【解决方案1】:

这是一个没有 jQ 技巧的更好的解决方案:

<p:socket channel="/table" >
    <p:ajax event="message" update=":datatable" />
</p:socket>

如果您不想丢失过滤器,这是一个更好的解决方案:

<p:socket channel="/table" >
    <p:ajax event="message" oncomplete="PF('datatableWidgetVar').filter()" />
</p:socket>

【讨论】:

    【解决方案2】:

    这是我的简单测试,当 2.xhtml 中的 soclet 从服务器接收到事件时,它会触发点击事件到命令按钮,并且这个命令按钮(你可以不可见)将更新你想要的目标: 豆:

    @ManagedBean(name = "globalCounter")
    @SessionScoped // option
    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>
    

    【讨论】:

    • 我有这个错误:严重:ResourceConfig 实例不包含任何根资源类。之后 java.lang.NullPointerException: null ...这些都发生在页面加载时。点击按钮之前!
    • 也许我在配置推送 servlet 时出错了……当我在 web.xml 中添加推送 servlet 配置时,会发生这些错误。
    • 我的配置:Push Servletorg.primefaces.push.PushServletPush Servlet/primepush/*
    • 然后在 web 文件夹的 primepush 文件夹中创建 1.xhtml 和 2.xhtml。
    • atmosphere-compat-jbossweb-1.1.0.RC1.jar annotation-detector-3.0.1.jar大气-compat-tomcat-1.1.0.RC1.jar大气-compat-tomcat7-1.1 .0.RC1.jar 大气运行时-1.1.0.RC1.jar
    猜你喜欢
    • 2012-01-25
    • 2019-04-11
    • 2014-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多