Reputation: 55
I want to do something like that.
public class Bean
{
public void test()
{
System.out.println(System.currentTimeMillis());
}
}
<script>
window.setInterval(function()
{
//bean.test()
}, 1000);
</script>
I already played around with simulating button click etc. But it never really worked as it was supposed to. Either it didn't work at all or the test()-method was only called on page load.
I would be glad if someone has a working example :)
Upvotes: 0
Views: 715
Reputation: 953
If you are using Primefaces, you can use the <p:remoteCommand>
to call the backing bean via JavaScript.
<p:remoteCommand name="callback" actionListener="#{bean.test}"/>
<h:outputScript>
window.setInterval(function() {
callback();
}, 1000);
</h:outputScript>
Upvotes: 1
Reputation: 7469
this is what you are looking for:
<h:form id="form">
<h:outputText id="txt_count" value="#{counterBean.count}" />
<p:poll interval="3"
listener="#{counterBean.increment}" update="txt_count" />
</h:form>
Upvotes: 1