Tuesday, April 8, 2014

ADF Interview Question 2

Q: Lifecycle of a Web Page Request Using Oracle ADF and JSF
Ans : Below figure  shows a sequence diagram of the lifecycle of a web page request using JSF and Oracle ADF in tandem.

Lifecycle of a Web Page Request Using JSF and Oracle ADF



Q : What are the various access scopes supported by ADF?
A : ADF Faces supports the following scopes
    • none
    • backingBean
    • request
    • view
    • pageFlow
    • session
    • application

Memory Scope for ADF Managed Beans

ScopeDescription
application
The application scope lasts until the application stops. Values that you store in a managed bean with this scope are available to every session and every request that uses the application.
Avoid using this scope in a task flow because it persists beyond the life span of the task flow.
session
The session scope begins when a user first accesses a page in the application and ends when the user's session times out due to inactivity, or when the application invalidates the session.
Use this scope only for information that is relevant to the whole session, such as user or context information. Avoid using it to pass values from one task flow to another. Instead, use parameters to pass values between task flows. Using parameters gives your task flow a clear contract with other task flows that call it or are called by it. Another reason to avoid use of session scope is because it may persist beyond the life span of the task flow.
pageFlow
Choose this scope if you want the managed bean to be accessible across the activities within a task flow. A managed bean that has a pageFlow scope shares state with pages from the task flow that access it. A managed bean that has a pageFlow scope exists for the life span of the task flow.If another task flow's page references the managed bean, the managed bean creates a separate instance of this object and adds it to the pageFlow scope of its task flow.
view
Use this scope for managed bean objects that are needed only within the current view activity and not across view activities. It defines scope for each view port that ADF Controller manages, for example, a root browser window or an ADF region.
The life span of this scope begins and ends when the current viewId of a view port changes. If you specify view, the application retains managed bean objects used on a page as long as the user continues to interact with the page. These objects are automatically released when the user leaves the page.
request
Use request scope when the managed bean does not need to persist longer than the current request.
backingBean
A backing bean is a convention to describe a managed bean that stores accessors for UI components and event handling code on a JSF page. It exists for the duration of a request and should not be used to maintain state.
Use this scope if it is possible that your task flow appears in two ADF regions on the same JSF page and you want to isolate each instance of ADF region.



Q : How to Skip Validation in ADF using SkipValidation?

A : This method mainly used for Model layer validation skip.
ADF has a very robust validation framework. Validations can be added at different layers (view, model and business services) based on your application's requirement. To learn more about the ADF validation framework, please go through the Fusion Developer's Guide for Oracle Application Development Framework.
That said, however, in a real business scenario there are cases where the validation needs to be skipped (or by passed) conditionally while submitting the form. This post discusses this topic with some common use cases.

Keep immediate=true

A very common way to skip validation is by keeping the value for immediate attribute as 'true' for the UIComponents. Immediate attribute allow processing of components to move up to the Apply Request Values phase of the lifecycle.


scenario:

While canceling a specific action, system should not perform the validation. One possible way to achieve this is by keeping immediate=true associated with UI element. To know more abut this feature, please refer this wiki.

Sometimes you may need to update UI controls with model data as part of the ‘immediate’ action. Make sure that you call resetValue() on the UIInput in this scenario. This causes to reset the submitted value and would ensure that UI gets updated with right value from the model.


SkipValidation

Another approach is to use SkipValidation property associated with the page definition file.SkipValidation by pass the model layer validation based on the specified parameter value.

Please note that:

1. This doesn’t have any impact on JSF/ADF Lifecycle.

2. This property doesn’t have any effect on the client side validation (even if it is generated using the EL bound with model layer)


Where can I locate SkipValidation?

SkipValidation can be located as part of the root node of the page definition file.


Possible values for SkipValidation are given below.


a. SkipValidation=true

Setting ‘SkipValidation’ property to true will bypass the ADF Model validation. In this case validation happens only when you commit the transaction( i.e: when you call transaction.commit()). Please note that SkipValidation skips only the entity level validation. The attribute level validation fire irrespective of the value for the boolean flag


Scenario:

This is useful where you need to delay the validation till the point where transaction gets committed to Database. There are cases where business data needs to be captured in bulk. A typical example would be capturing transaction data using a grid form/tabular list. Business user must be able to key in values in any order. i.e. even without completing the data capture for the current record, user must be able to move to next set of records. Here model level validation needs to be delayed till we really save the data. SkipValidation=true is the right option to achieve this sort of use case, which does the validation across records, only while committing the transaction.


b. SkipValidation=custom

In this case, framework validates only the 'CustomValidator' specified in page definition file.

The value of the 'CustomValidator' property would be an EL expression that evaluates to a bean that implements the "oracle.binding.BindingContainerValidator interface"


Scenario:

This gives more control to the developer while validating the data. Only validates(or rather executes) what is given in custom implementation for BindingContainerValidator. It is much useful in complex business scenarios where developer needs finer control on validation.


c. SkipValidation=skipDataControls

skipDataControls means that it will skip the data control level validation (also known as Transaction Level validation) and instead only will validate data in the row or rows which got updated through iterator in the current binding container.


Scenario:

The property is very much useful while dealing with below given scenarios.

1. A single entity is mapped to multiple tabs in a page.

2. Same page is making use of multiple Data Controls. Here commit on one Data Control should not trigger validation on other Data Controls defined in the same page.


d. SkipValidation=false

This is the default value for SkipValidation, apparently this setting just ensures the normal flow for validation during form submission.


Q.What is Application Module?
A: An ADF components application module is a service object that coordinates view objects for a specific task in the same way that a form usually encapsulates a single user task. It contains only the business services that the application requires, and can be compared to a Forms module.
An application module can represent and assist with tasks such as:
·  Updating customer information
·  Creating new order

·  Processing salary increases.


Q : What is the return type of Service Methods?
A : Service Methods can return Scalar or Primitive Data types.

Q : Can Service Methods return type Void?
A : Yes, Service Methods can Return type Void

Q : Can Service Methods return Complex Data types?
A : No, service methods can return only primitive/scalar data types.

Q : Which component in ADF BC manages transaction ?
A : Application Module, manages transaction.

Q : Can an entity object be based on two Database Objects(tables/views) or two Webservices ?
A : No entity objects will always have one to one relationship with a database object or web service.

Q : Where is that we write business rules/validations in ADF and why?
A : We should be writing validations at Entity Object level, because they provide highest degree of reuse.

Q : What are the various access scopes supported by ADF?
A : ADF Faces supports the following scopes
    Application Scope
    Session Scope
    PageFlow Scope
    Request Scope
    BackingBean Scope.

Q : What is the purpose of adfc-config.xml?
A: The adfc-config.xml file is the configuration file for an ADF unbounded task flow. This file contains metadata about the activities and control flows contained in the unbounded task flow.

Q : What is the purpose of faces-config.xml?
A: Use the faces-config.xml file to register a Framework application’s resources, such as custom validators and managed beans, and to define all page-to-page navigation rules.

Q : In which xml do you configure the skin for your framework application?
A: trinidad-config.xml

Q : How do you decide whether the application should be deployed as an EAR or a WAR?
A: If the application contains run-time customizations using MDS, it must be bundles as an EAR. For simple webcenter portal application with no such customizations, WAR can be created.

Q : What is the purpose of jazn-data.xml?
A: This file is used for defining the permissions and privileges for various groups of users on various taskflows created in the application.

Q : When we drag drop VO from DataControl which binding occurs?
A: Value binding occurs.

Q : Explain Data binding & its types, sub-types?
A : Oracle Application Development Framework (Oracle ADF) provides several types of binding objects to support the attributes and operations exposed by the Oracle ADF data controls for a particular business object:
  • Iterator binding, one per accessor attribute that your page or panel displays. Iterates over the business objects of the data collection and maintains the row currency and state.
  • Value bindings, one for each data-bound UI component. Provides access to data.
  • Action binding, specifically defined for a button component. Provides access to operations defined by the business object.
Value Binding Types:
1. Attribute Value Binding
2. Boolean Value Binding 
3. List Value Binding 
4. Range Value Binding
5. Scroll Value Binding



Q: Explain Data Control Palette hierarchy
A: Data Control Palette hierarchy:The Data Control Palette displays two types of actions:
  • Actions that typically operate on all data collections in the current web page's binding context (such as Commit and Rollback) in the Operations folder at the root level of the hierarchy.
  • Operations on a specific data collection (for example, MyView1). Data collection-specific operations (such as Create and Delete) appear in the Operations folder as child nodes of the collection in the Data Control Palette.
Q: Write  code to access the current row and or the view object inside your bean.

A:  code to access the current row and or the view object inside your bean:


BindingContainer bc = BindingContext.getCurrent().getCurrentBindingsEntry();
DCBindingContainer dcbc = (DCBindingContainer) bc;
DCIteratorBinding lBinding = dcbc.findIteratorBinding("EmployeesViewIterator");
EmployeesViewRow row = (EmployeesViewRow) lBinding.getCurrentRow();
EmployeesView view = (EmployeesView) lBinding.getViewObject();

You have to change the iterator name 'EmployeesViewIterator' to the name of your VO iterator (look it up in the page bindings) and the classes Employees.

Monday, March 24, 2014

Array List Implementation in JAVA

Write a program to implement your own ArrayList class. It should contain add(), get(), remove(), size()  methods. Use dynamic array logic. It should increase its size when it reaches threshold.


 import java.util.Arrays;

public class MyArrayList {
        
    private Object[] myStore;
    private int actSize = 0;
    
    public MyArrayList(){
        myStore = new Object[10];
    }
    
    public Object get(int index){
        if(index < actSize){
            return myStore[index];
        } else {
            throw new ArrayIndexOutOfBoundsException();
        }
    }
    
    public void add(Object obj){
        if(myStore.length-actSize <= 5){
            increaseListSize();
        }
        myStore[actSize++] = obj;
    }
    
    public Object remove(int index){
        if(index < actSize){
            Object obj = myStore[index];
            myStore[index] = null;
            int tmp = index;
            while(tmp < actSize){
                myStore[tmp] = myStore[tmp+1];
                myStore[tmp+1] = null;
                tmp++;
            }
            actSize--;
            return obj;
        } else {
            throw new ArrayIndexOutOfBoundsException();
        }
        
    }
    
    public int size(){
        return actSize;
    }
    
    private void increaseListSize(){
        myStore = Arrays.copyOf(myStore, myStore.length*2);
        System.out.println("\nNew length: "+myStore.length);
    }
}