Thursday, September 26, 2013

How to Invoke commandButton's action programatically at Runtime?

 How to Invoke commandButton's action programatically at Runtime?

   public String initiate() {
     
        FacesContext facesContext = FacesContext.getCurrentInstance();
        UIViewRoot root = facesContext.getViewRoot();
     
        RichCommandButton button = (RichCommandButton) root.findComponent("cb2"); //"cb2" is the Id of the CommandButton
        ActionEvent actionEvent = new ActionEvent(button);
        actionEvent.queue();
        System.out.println("Exiting from initiate()....");
        return null;
    }