Wed. Jan 26th, 2022

Requirement: There will be many cases where we will need to invoke button action, or button actionListener, on any component’s valueChnageListener.

For example, say we have a button on click of which it opens a popup with dialog displaying a message as “Welcome to the world of Oracle ADF!”. But here instead of directly clicking on the button we will call the actionListener code of the button on valueChangeListener event of an inputText.

Thus, in this post I will describe how we can achieve the above stated functionality.

Explanation: Oracle ADF provides a facility to queue action event one after another, which means we can perform multiple actions by queuing.

Solution: For solution of the above requirement follow the steps as shown below:

Step 1: Create an Oracle ADF Fusion Web Application.

Step 2: Create a demo.jspx page. Drag and drop af:panelFormLayout inside the demo.jspx page.

Drag and drop an af:inputText inside the af:panelFormLayout. Set label=”Name”, and autoSubmit=”true”. Create a valueChangeListener event as valueChangeListener=”#{pageFlowScope.MyBean.nameVCL}”

Drag and drop af:button. Set text=”Show Entered Name in Popup”. Create actionListener=”#{pageFlowScope.MyBean.launchPopupAL}”

Drag and drop af:popup and set binding=”#{pageFlowScope.MyBean.openPopupBinding}”

Drag and drop af:dialog inside the af:popup.

Drag and drop af:outputText inside the af:dialog and set value=”Welcome to the world of Oracle ADF!”

Thus, the complete code for the demo.jspx page is shown below:

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="" version="2.1" xmlns:f=""
          xmlns:af="">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <f:view>
        <af:document title="demo.jspx" id="d1">
            <af:form id="f1">
                <af:panelFormLayout id="pfl1">
                    <af:inputText label="Name" id="it1" valueChangeListener="#{pageFlowScope.MyBean.nameVCL}"
                                  autoSubmit="true"/>
                    <af:button text="Show Entered Name in Popup" id="b1"
                               actionListener="#{pageFlowScope.MyBean.launchPopupAL}"/>
                    <af:popup childCreation="deferred" autoCancel="disabled" id="p1"
                              binding="#{pageFlowScope.MyBean.openPopupBinding}">
                        <af:dialog id="d2">
                            <af:outputText value="Welcome to the world of Oracle ADF!" id="ot1"/>
                            <f:facet name="buttonBar"/>
                        </af:dialog>
                    </af:popup>
                    <f:facet name="footer"/>
                </af:panelFormLayout>
            </af:form>
        </af:document>
    </f:view>
</jsp:root>

The complete code for MyBean.java file is as below:

package susantotech.com;

import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;

import oracle.adf.view.rich.component.rich.RichPopup;
import oracle.adf.view.rich.component.rich.nav.RichButton;

public class MyBean {
    private RichPopup openPopupBinding;

    public MyBean() {
    }

    public void nameVCL(ValueChangeEvent valueChangeEvent) {
        if (valueChangeEvent.getNewValue() != null) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            UIViewRoot root = facesContext.getViewRoot();
            RichButton button = (RichButton) root.findComponent("b1");
            /*
             * //To be used when we are invoking the button which is within a region
             * (for example) and say the region id is r1
             * RichButton button = (RichButton) root.findComponent("r1:b1");
            */
            ActionEvent actionEvent = new ActionEvent(button);
            actionEvent.queue();
        }
    }

    public void setOpenPopupBinding(RichPopup openPopupBinding) {
        this.openPopupBinding = openPopupBinding;
    }

    public RichPopup getOpenPopupBinding() {
        return openPopupBinding;
    }

    public void launchPopupAL(ActionEvent actionEvent) {
        RichPopup.PopupHints hints = new RichPopup.PopupHints();
        this.getOpenPopupBinding().show(hints);
    }
}

Save all and run the application. Thus, the ran application is shown below:

Enter value in the Name field and the moment we moved out of the Name field, the valueChangeListener of the Name field inputText is called, inside which the actionListener code of the button gets called. Thus, we can see the popup is launched. The code for the launch of the popup is inside the actionListener method of the button.

Hence, the solution to our requirement.

If you like the post please comment, share, and do join me on Facebook. Please subscribe to my YouTube Channel for video tutorials.

Thanks & Regards,
Susanto Paul

 858 total views,  1 views today

By Susanto Paul

Susanto is an Oracle ACE, a qualified MCA, MBA, and a highly-skilled Senior Oracle Specialist. He is an enthusiastic Blogger and YouTuber who helps learners to solve their complex problems more efficiently. He has 9+ years of experience in multiple technologies like AWS, Oracle ADF, Oracle APEX, Oracle JET, Oracle VBCS, Oracle IDCS, Oracle PL/SQL, Oracle Integration Cloud, Java, JDBC, Servlets, JSP, Spring, Hibernate, HTML5, CSS3, JavaScript, TypeScript, NodesJS, Angular, MySQL, Oracle WebLogic Server, JUnit, JMeter, Selenium Web Driver, etc. He is a certified: Oracle Certified Professional Java SE 6 Programmer, Oracle ADF 11g Certified Implementation Specialist, Oracle Cloud Platform Application Integration 2020 Certified Specialist, Oracle Cloud Infrastructure Foundations 2020 Certified Associate, and Oracle Cloud Infrastructure Developer 2020 Certified Associate

Leave a Reply

Your email address will not be published. Required fields are marked *

satta king chart