Invoke button’s action programatically in JSF using Java

Environment (JDeveloper,  ADF Faces)

Sometimes developers may want to invoke button’s action programatically without needing a user to click a button, a common use case for this scenario is implementing navigation propgramatically using Java, 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”);
ActionEvent actionEvent = new ActionEvent(button);


Filed under ADF

3 responses to “Invoke button’s action programatically in JSF using Java

  1. raul

    fue de mucha ayuda gracias

    • After recognizing that this is a Spanish, the translation is: was very helpful thanks. and I say you are more than welcome.
      In Spanish, más que bienvenido. 🙂

  2. diego

    nevermind It was my mistake, thanks a lot!!

Leave a Reply to raul Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s