ADF Questions with Answers & Code snippets – Part1

Q) what is the job of ‘C’ in MVC architecture: ?
The Controller’s job is to translate incoming requests into outgoing responses. In order to do this, the controller must take request data and pass it into the Service layer. The service layer then returns data that the Controller injects into a View for rendering.

Q) what is the job of ‘V’ in MVC architecture: ?
The View’s job is to translate data into a visual rendering for response to the Client (ie. web browser or other consumer). The data will be supplied primarily by the Controller; however, the View may also have a helper that can retrieve data that is associated with the rendering and not necessarily with the current request (ex. aside data, footer data).

Q) what is the job of ‘M’ in MVC architecture: ?
The Model’s job is to represent the problem domain, maintain state, and provide methods for accessing and mutating the state of the application. The Model layer is typically broken down into several different layers:

Q) How to Crete Data Controls using Business Components: ?
way1 : Create EO – Create VO from EO – Created AppModule – Add the VO to AppModule – Then ADF will create
Data Controls automatically after adding to AppModule

way2 : Create Read Only VO/VO based on staticList (Transient VO) – Create App Module – Add the VO to AppModule – Then ADF will create Data Controls automatically after adding to AppModule

Q) How to Create Data Controls using POJO Class: ?
POJO class -> The Java class which contains only variables and its accessor methods
Managed Bean -> The Java class to which scope has been registered either in faces-config.xml or adfc-config.xml

1) Create a POJO class with the required variables and its accessors
and the Default constructor should have the arguments which we want to show in the data controls.
2) Create a Managed Bean and create a List of POJO class data type.
3) Add the required variables to the created list by Calling POJO class default constructor by passing the required variables as arguments from the default constructor of Managed bean

Assume Name of POJO class is -> staticTablePojo
Name of Managed bean is -> staticTable
Managed bean Code ->
List<staticTablePojo> personList = new ArrayList();
public staticTable() { // default constructor of Manged bean
personList.add(new staticTablePojo(“Ravi”, “xxxxxxxxxx”, 50000));
personList.add(new staticTablePojo(“Teja”, “xxxxxxxxxx”, 50000));
personList.add(new staticTablePojo(“Yellina”, “xxxxxxxxxx”, 50000));
POJO class Code -> (It has variables Name, mobNo, salary and its accessor methods)
public staticTablePojo(String name, String moNo, Integer salary) { // default constructor of POJO class
this.Name = name;
this.mobNo = moNo;
this.salary = salary;

Q) How to Add Faces Meassage πŸ˜•
we can add the Faces message from the Managed bean wich will get displayed in the Page as popup msg.
we can add the Faces message from the Managed bean wich will get displayed in the Page inline with a
particular component.

public String showMessage() {
String messageText=”A prgramatic af:message”;
FacesMessage fm = new FacesMessage(“messageText”);
/* set the type of the message.
* Valid types: error, fatal,info,warning (SEVERITY_ERROR, SEVERITY_INFO, SEVERITY_WARN, SEVERITY_FATAL )
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, fm);
return null;
The last lines can be Following for displaying Message popup inline to a component
(DepartmentName is an input text whose binding property is set to
binding= #{showMessage.it1} which is declared in the Managed bean as “private RichInputText DeptName;”
//departmentName is the binding property for our field.
context.addMessage(getDeptName().getClientId(context), fm);

Note: By default the Message will be displayed as popup. We can change it to display as part fo the
page for that need to set the inline property of af_message to true.

Q) Give a Simple Real Time example of using different context classes in ADF : ?

AdfFacesContext: (Mainly Used for PPR (to partial refresh a component)

RichPanelGroupLayout rpgl =
// This is accessing the component using its ID (Not Preferrable)
RichPanelGroupLayout rpgl;


ADFContext: (Mainly Used to get/set the different scopes)

String nomphyval =

FacesContext: (Mainly used To add Faces Message, to get Local (client) IP and Remote (server) IP details)
(import oracle.adf.faces.context.FacesContext;)
FacesMessage fm = new FacesMessage(“You Account is Invalid”);
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, fm);
RequestContext: (Mainly used to get the Agent details)
(import org.apache.myfaces.trinidad.context.RequestContext;)
RequestContext requestCtx = RequestContext.getCurrentInstance();
Agent agent = requestCtx.getAgent();
String version = agent.getAgentVersion();
String browser = agent.getAgentName();
String platform = agent.getPlatformName();
String platformVersion = agent.getPlatformVersion();

Q) How to get the Local IP, Remote IP address in Managed Bean πŸ˜•

FacesContext fctx = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) fctx.getExternalContext().getRequest();


Q) Difference between Binding Layer and Data Controls πŸ˜•

Binding layer uses the Data Controls to deal with the data.
Binding layer on a whole provides a consistent interface to the data regardless of where it comes from there by giving freedom to the end users to implement their UI’s based on the binding layer.

Source of Data to disply on UI (Data Model)-> EJB, WebService, JavaList, Database
For all of these you Have to create the Data Controls to use them in view
Once You Create Data Controls then you have to bind these data controls to the UI components
So For that Binding Layer comes into Picture.
The binding layer is based on JSR-227 a Java specification standard

A data control is the one that packages the data model and exposes access interface which can later be used by the binding layer to deal with data.(Can be considered as the implementation of the JSR-227 interface)


Q) Binding Layer vs Model Layer: ?


So To get the Bindings of a page first we need Binding Context and then we have to get the Binding Container. From Binding Container we can get any type of bindigns (List, Attribute, operation, Tree, Iterator Bindings) used in the page.
List, Attribute, operation, Tree bindings -> these links to Iterator binding
Iterator binding (DCIteratorBinding)-> links to collection that you queried from the business services.
It interacts with the RowIterator objects to iterate over collections and provide the current row

Q) Any relation b/w PageDefinition File and BindingContainer : ?
PageDefinition and BindingContainer both are same. Both represent the same i.e bindings.
PageDefinition file -> is a Design time represention of Bindings in the form of Meta Data
BindingContainer -> is a Run time representaion of Bindings as java objetcs
Note: At Run time the Meta data created at design time is used to Configure the Java class.
All generic Binding Classes starts with JUCtrl
Specific ADF Faces binding Classes starts with FacesCtrl

Q) How to Access Different types of Bindings in Managed bean πŸ˜•
get BindingContext object first using “BindingContext.getCurrent()” and using that get the BindingContainer object.

BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorbinding iterBind = (DCIteratorbinding)bindings.get(“IteratorName”);
Table, Tree Table Bindings:
JUCtrlHierBinding tabBind = (JUCtrlHierBinding)bindings.get(“TableBindName”);
Commonly used methods -> getRootNodeBinding, getTypeBindings, findNodeByKeyPath
JUCtrlListBinding tabBind = (JUCtrlListBinding)bindings.get(“ListBindName”);
AttributeBinding attrBind = (AttributeBinding)bindings.get(“AttrBindName”);
OperationBinding attrBind = (OperationBinding)bindings.get(“OperBindName”);

Q) Example of using different bindings in java : ?
AttributeBinding: Change the attribute value(appedna a value to the existing value)
AttributeBinding attrBind = (AttributeBinding)bindings.get(“AttrBindName”);
String oldVal = attrBind.getInputValue();
String newVal = (oldVal+”newValue”);
OperationBinding: Execute the operation bindings by passing the required parameter values to it
OperationBinding attrBind = (OperationBinding)bindings.get(“OperBindName”);
ListBinding: Get the value selected in SelectOneChoice component in the webpage
JUCtrlListBinding tabBind = (JUCtrlListBinding)bindings.get(“ListBindName”);
For Single select choice->
String selectedValue = listBinding.getSelectedValue().toString;
For multi select choice->
ViewRowImpl selectedListRow = (ViewRowImpl)listBinding.getSelectedValue();// get current row 4m listBind
String jobIdValue = (String)selectedListRow.getAttribute(“JobId”); // get reqd attr val from current row
Number MaxSalary = (Number)selectedListRow.getAttribute(“MaxSalary”);// get reqd attr val from current row
Q) How to get the VO and execute in AmImpl Class : ?

public void Dept(){
ViewObject vo = this.findViewObject(“EmployeesVO”);
// here findViewObject method will find any view objet that is added to the Application Module
// And we can also use findViewLink to find any view link which are present in the Application Module

Q) How to get VO and execute in Managed bean : ?

String amDef = “test.TestModule”; // complete name from root level package (here ‘test’ is package name)
String config = “TestModuleLocal”; //Click on AppModule -> Configurations -> take the Local name
ApplicationModule am = Configuration.createRootApplicationModule(amDef, config);
ViewObject vo = am.findViewObject(“EmployeesVO”);
Note: -> Here we are getting the AM from AM Pool and this should be returned back to AM Pool. so when ‘createRootApplicationModule’ method is used then call ‘releaseRootApplicationModule’ method at the end if u are not using that AM instance anymore.
-> Accessing the AM uisng the method ‘createRootApplicationModule’ is not preferrable.
because the AM which the page is currently using is different from the AM which we are getting through programatically fron AM Pool. And if we not properly return the instances back to AM Pool leads to performance degrade. So when u wnat to call any mthods from AM then crete the methods in AMImpl calss and expose them to client UI and use them. instead of taking AM from AM pool in managed bean

Q) How to add script from Managed bean to JSF page : ?

ExtendedRenderKitServiec erks = Service.getRenderKitService();
erks.addScript(FacesContext.getCurrentInstance(),” function ravi () { alert(‘Hi’);”);

Q what components we should use for user customizaton or personalizaion πŸ˜•
We have to use the Composer Components which are like ADF Faces
Composer Components (LayoutCustomizable,PanelCustomizable,ShowDetailFrame)

Q) Explain the role of ADF Binding Filter : ?
public class ADFBindingFilter
extends java.lang.Object
implements javax.servlet.Filter
The ADFBindingFilter is used to pre-process any http requests to resources that may require access to the ADF runtime. It is responsible for: – Initializing the Binding Context for a user’s http session. – Serializing all incoming http requests within a session. – Notifying data control instances that a request is about to be served. – Notifying data control instances after the response has been served to the client.

Q) How ADFBindingFilter class will Intialize the BindingContext:?
on page load ADFBindingFilter class Initalizes the binding context by reading the CPX file defined by the ‘CpxFileName’ init parameter.
-> Means it’ll find the <CpxFileName from META-INF->adfm.xml>.cpx file and then read the DataBindings.cpx file which has all the page paths and and its pagedefinition file paths. So it’ll find current page related pagedefinition file which has all the bindings meta data which the current page is uisng.
-> Once it got the meta data file it’ll Initialize the BindingsContext for the page by calling initializeBindingContext method present in it.
Means customizing the java class at run time from the design time generated metadata file.
(Model {BindingContext} = BindingContainer + Data Controls)
public static BindingContext initializeBindingContext(javax.servlet.http.HttpServletRequest request)

In Short:
-> on page load ‘HTTPServletRequest’ will get
-> ADFBindingFilter servlet class will get invoked as it is defined as a Filter in web.xml
-> This servlet class checks the request wheather it requires access to the ADF runtime . If Yes
-> Read .cpx file path from adfm.xml -> search related pageDef(BindignsMetaData File) file for Current page in .cpx file
(Till now -> It got design time Meta data file for bindins and now it’ll customize the java class for the bindings using the design time meta data)
-> Initialize BindingContext for the current page by calling method ‘initializeBindingContext(HttpReq req)’
( Now it has the BindingContext means complete accesss to Model Layer (BindingContainer+Datacontrols)
-> Now uisng the run time binding classes the data will be fetched from the business services
-> Then the fetched data will be displayed in the JSF page.
Q) autoSubmit vs partilaSubmit πŸ˜•
They are both AJAX enabled calls occurring from custom properties of custom JSF components. The autoSubmit essentially asynchronously postsback content specific to the component for keeping the server side managed bean values current with the content within the component on the client side.

A partialSubmit is another asynchronous AJAX call that will serve to immediately postback a component value on some kind of component event, like losing focus on an ICEFaces inputText component for example.

The interesting thing to note is that the entire ViewState is posted back on each type of asynchronous submit, so if the values of other components HAD changed on the page before the submit, the bound server side managed bean properties will have their values refreshed as well, even though the client side components MAY not be refreshed to reflect any server side data changes that may have occurred.

In fact, the entire JSF server side lifecycle occurs on each postback, read the following article on implementing a debug PhaseListener that allows you to see what Phases are occurring after each asynchronous submit operation occurs.
Q) Code to redirect to other page from ManagedBean πŸ˜•
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletRequest req = (HttpServletRequest) facesContext.getExternalContext().getRequest();
HttpServletResponse res = (HttpServletResponse) facesContext.getExternalContext().getResponse();

Q) Rest webservices Calling: (using HttpClient Libraries)
what we need to impor->

-> Pass the Header Information uisng HttpPost Method to get the authentication token.
-> Pass this token uisng HttpGet method along with required webservice request url to get the required results.

HttpClient client = new DefaulatHttpClient(); // getting HttpClient Object
HttpPost post = new HttpPost(“url”); //getting HttpPost Object by passing required url
StringEntity input = new StringEntity(“<username>ravi</username><password>ravi</password”);
// get StringEntity objet by passing required header info and set its format type

post.setEntity(input); // setting the Header info object to the Post method
HttpResponse response = client.execute(post);

BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent));

while(rd.readLine() != null){
String postResponse = rd.readLine().toString();
Β Q) BufferedReader vs InputStreamReader: ?
-> Buffered Reader is a wrapper of InputStreamReader/FileReader
-> Means InputStreamReader is a specialization of BufferedReader. It converts byte stream to character stream
-> BufferedReader is Generalization of InputStreamReader
-> Here the the getContent method returns byte stream. so first taking it into InputStreamReader and then taking (generalizing) to BufferedReader