FROM THE BLOG

ADF Tips: How to get value of UI Components.

We can see often developers asking on the OTN JDeveloper & ADF Forum about how to get the value of an UI Component like an input text or selectOneChoice, etc. There are several ways to do it. The common way developers use to go for is binding the component to a bean and then accessing its value by calling myComponent.getValue(). But what happens when the scope of your bean is not Request or BackingBean ?

UI Components and NOT SERIALIZABLE. If your ADF Application will be deployed in a High Availability Environment (Clusters and Nodes) where user sessions need to be replicated across the nodes, every class with scope greater than Request needs indeed to be serializable. Having say that, becomes clear why you should never bind UI Components to beans with ViewScope, PageFlowScope or even worst SessionScope. 

Have you heard about client attribute? It can be attached to pretty much anything that will trigger an event in the server, and it can be accessible from your java code in just one line of code. Lets see an example;

When we click the “Test” button, an actionListener will be called, and from there we want to access the DepartmentName inputText value. With our approach, we select the “Test” button and insert a client attribute.

Capture

Then, we give a meaningful name and its value will be exactly what the DepartmentName inputText value is

Capture1

 

Our “Test” button will execute the testMethod actionListener and this is how it looks:

 

Capture2

 

This will be enough to get the value we are looking for, clicking on Test button in each screen;

Capture3 Capture4

This is what the console prints:

Capture5

 

You can check out this other article which shows 4 other different ways of accomplishing the same (few of them requires a bean to be maximum at request scope). Visit here.

 

Leave a comment

Your email address will not be published.

Social Media

Stay up-to-date with our latest ADF and related technical posts via your favourite social network services.