1

I havent worked out how to call/invoke a method dynamically without using the @PostContruct method and initialising @ the page creation.

At the moment I am simply trying to get the primeface p:poll example working. I have placed the method in its own class for now to keep it clean and simple & looks like so:

    @ManagedBean(name="counterBean")
    @SessionScoped
    public class CounterBean implements Serializable {

    private int count;

    public int getCount() {  
        return count;  
    }  

    public void setCount(int count) {  
        this.count = count;  
    }  

    public void increment(ActionEvent actionEvent) {  
        setCount(getCount() + 1);  
    }  
} 

And then the xhtml code:

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

Intellisense within netbeans tells me that the "increment" part of #{counterBean.increment} is an "Unknown Property" i.e. it cant find the method. So how can I get JSF to recognise and invoke this method from the xhtml?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Ally
  • 1,476
  • 3
  • 19
  • 30

1 Answers1

1

Well after a some head scratching the p:poll component started working after a slight adaptation from the primefaces demo & manual. Change the p:poll listener to actionListener:

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

Also ensure that your html page/template is surrounded by the <f:view contentType="text/html"> tag

Hope this helps someone & thanks to BalusC for his help in debugging this.

Ally
  • 1,476
  • 3
  • 19
  • 30