Sun. Oct 24th, 2021

Objective: Now the main objective of this post is to show you in how many ways we can get the values of the UI components programmatically in bean.

We can see that many Software Developers asking questions on how to get the values of the ADF UI components in the bean. As of now I am aware of two ways to get the values of the UI component in bean.

The first way is to create the binding of the UI component to the bean and then accessing its value by calling this.getComponentBinding().getValue().toString().

The second way is by using af:clientAttribute inside the component that will fire the event to get the values, like af:button.

Requirement: I have a demo.jspx page. On that page I have two af:inputText, one af:outputText and one af:button components. The af:button names is: “Get Values” , and the af:inputText labels are “First Name” and “Last Name”. Set the value of the af:outputText as value=”#{viewcontrollerBundle.HELLO}”.

Now, when I click on the af:button, it should display the af:inputText values and the af:outputText value in the bean.

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 in the ViewController project of our application.

Step 3: Drag and Drop one af:button, one af:outputText and two af:inputText from the component palette on the demo.jspx page.

Name the two af:inputText label as First Name and Last Name. Create the binding for the first af:inputText as binding=”#{pageFlowScope.MyBean.firstNameBinding}”.

Set the value of the second af:inputText as value=”Deb”

Set the value of the af:outputText as value=”#{viewcontrollerBundle.HELLO}”.

Name the af:button as “Get Values“. Create an actionListener for all the af:button. Thus, the actionListener for the created af:button is actionListener = “#{pageFlowScope.MyBean.getValues}”. Now drag and drop af:clientAttribute inside the af:button. Set the value of the af:clientAttribute as “Deb”. The value should be exactly same as the value of the Last Name af:inputText component and give any name for the af:clientAttribute. In this case I have give name=”lastName”. This will help us to get the value of the component in MyBean,java class

Similarly again drag and drop af:clientAttribute inside the af:button. Set the value of the af:clientAttribute as value=”#{viewcontrollerBundle.HELLO}”. The value should be exactly same as the value of the af:outputText component and give any name for the af:clientAttribute. In this case I have given the name as name=”greeting”.

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

Step 4: Now go to the MyBean.java and write the codes for getValues method. Thus, the complete MyBean.java code is shown below:

package com.susanto;

import javax.faces.event.ActionEvent;

import oracle.adf.view.rich.component.rich.input.RichInputText;

public class MyBean {
    private RichInputText firstNameBinding;

    public MyBean() {
    }

    public void getValues(ActionEvent actionEvent) {
        String fname = this.getFirstNameBinding()
                           .getValue()
                           .toString();
        System.out.println("First Name is : " + fname);
        String lname = actionEvent.getComponent()
                                  .getAttributes()
                                  .get("lastName")
                                  .toString();
        System.out.println("Last Name is : " + lname);
        String greet = actionEvent.getComponent()
                                  .getAttributes()
                                  .get("greeting")
                                  .toString();
        System.out.println("The greeting message is : " + greet);
    }

    public void setFirstNameBinding(RichInputText firstNameBinding) {
        this.firstNameBinding = firstNameBinding;
    }

    public RichInputText getFirstNameBinding() {
        return firstNameBinding;
    }
}

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

Step 6: Now we will type some value say (Moumita) in the af:inputText component that is inside First Name af:inputText as shown below:

Now when I will click the “Get Values” then we get the values of the two af:inputText that is the values of the First Name and the Last Name as well as the value of the af:outputText printed in the MyBean.jav class as shown below:

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

 413 total views,  2 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