Queue an action event or invoking the button action in programmatic way in JSF /ADF – Techartifact

Sometimes our requirement is to invoke the button’s action in programmatic way without needing a user to click a button,. For example we want navigation happening automatically without clicking the button by user i.e implementing navigation in programmatic way using Java.We can queue an action event . In this case the developer may drag and drop a button in the page and binds its action property to some static action outcome or to a method that returns a String, and set Visible property for the button to false. At some point the developer can invoke this button’s action by using this code.

 

FacesContext facesContext = FacesContext.getCurrentInstance();
UIViewRoot root = facesContext.getViewRoot();   
//cb1 is the fully qualified name of the button
RichCommandButton button = (RichCommandButton) root.findComponent(“cb1″); // cb1 will be id of invisible button
ActionEvent actionEvent = new ActionEvent(button);
actionEvent.queue();        // we are queuing the all action programmaticly

an another code snippet which will work in this scenario

 

        UIComponent component = null;
        FacesContext facesContext = FacesContext.getCurrentInstance();
        if (facesContext != null) {
          UIComponent root = facesContext.getViewRoot();
          component = findComponent(root, "button_id");  // button_id will be id of invisible button
        }
        
        RichCommandButton button = (RichCommandButton)component;
        ActionEvent actionEvent = new ActionEvent(button);
        actionEvent.queue();   // we are queuing the all action programmaticly

Vinay

I am an Oracle ACE in Oracle ADF/Webcenter. Sr Java Consultant-working on Java/J2EE/Oracle ADF/Webcenter Portal/ content and Hibernate for several years. I'm an active member of the OTN JDeveloper/Webcenter forum. Passionate about learning new technologies. I am here to share my knowledge. Give your views and suggestion on [email protected] .

More Posts - Website

Follow Me:
TwitterLinkedInGoogle PlusYouTube