【问题标题】:how to call JSF bean method repeatedly and dynamically?如何重复动态地调用JSF bean方法?
【发布时间】:2014-04-08 23:13:11
【问题描述】:

我想做这样的事情。

public class Bean
{
public void test()
{
System.out.println(System.currentTimeMillis());
}
}




<script>
window.setInterval(function()
{
//bean.test() 

}, 1000);

</script>

我已经玩过模拟按钮点击等。 但它从来没有真正发挥应有的作用。 要么它根本不起作用,要么 test() 方法只在页面加载时被调用。

如果有人有一个可行的例子,我会很高兴:)

【问题讨论】:

    标签: java javascript jsf web


    【解决方案1】:

    这就是你要找的东西:

    <h:form id="form">
        <h:outputText id="txt_count" value="#{counterBean.count}" />
    
        <p:poll interval="3"
                listener="#{counterBean.increment}" update="txt_count" />
    </h:form>
    

    【讨论】:

      【解决方案2】:

      如果您使用 Primefaces,您可以使用 &lt;p:remoteCommand&gt; 通过 JavaScript 调用支持 bean。

      <p:remoteCommand name="callback" actionListener="#{bean.test}"/>
      
      <h:outputScript>
        window.setInterval(function() {
          callback();
        }, 1000);
      </h:outputScript>
      

      【讨论】:

        猜你喜欢
        • 2011-04-04
        • 1970-01-01
        • 1970-01-01
        • 2023-03-27
        • 2011-03-03
        • 1970-01-01
        • 2016-08-18
        • 2013-01-24
        • 1970-01-01
        相关资源
        最近更新 更多