Tuesday, October 8, 2013

ADF BC: Self View Object Link in Details VO


Usecase: Make a TermChildren accessor through self reference link in BudgetTerm

Steps:
  • Add new VO Link
  • Build the self association
    • select association between BudgetTermId in BudgetTermVO and BudgetTermParentId in BudgetTermVO also.
    • Add another association between BudgetFKId in BudgetTermVO and  BudgetFKId in BudgetTermVO also.
  • Rename accessors to TermChildren and TermRoot
  • Next to the end.

Tuesday, September 17, 2013

ADF BC: Default Values to President Attributes Using Groovy

Groovy default values do not work with president values well

  • Dependence work correct but groovy does not execute groovy expression because it returns null from second execution
  • You can use groovy default value expression for the first time success execution in president attribute by make it's updateable to never.
  • You can solve it pro-grammatically by:
    • In attribute set method of depended attributes
    • In attribute get method
      • Note: Must declare dependence in attribute dependence wizard


ADF BC: Validation Business Unit Group

  • Base entity validation included by default in rules & can not be override [even you remove the validation from parent entity].
1- 
      • Entity has no rule [only entity validation applied]
      • Entity has Rule 1 / Rule 2 based on switcher value

2-

      • Entity has no rule [only entity validation applied]
      • Entity has one of switcher 1 rules [ Rule 1 or Rule 2]
      • Entity has one of switcher 2 rules [ Rule 1 or Rule 2]
      • Entity has combination of switcher 1 & switcher 2 rules [ 4 Cases]

3- 
      • Entity has no rule [only entity validation applied]
      • Entity has rule 1 [Entity & added rule 1 validation applied]
      • Entity has rule 2 [Entity & override attributes from rule 1 validation only]


4-
      • Entity has no rule [only entity validation applied]
      • Entity has rule 1 [Entity & added rule 1 validation applied]
      • Entity has rule 3 [Entity & added rule 3 validation applied]
      • Entity has rule 4 [Entity & added rule 4 validation applied]
      • Entity has rule 2 [Entity & override attributes from rule 1 validation only]




ADF UI: Change Iterator Binding Depend on on LOV

Pre-Requirements: Table Employee and Department in HR schema

Use-case: List of values of all departments and when selection changes all employees in this department will display.

Steps:
  • Add method 'public void GetEmployeesInDepartment(Integer departmentId)' to AMImpl
    • Add departmentId to bind variable in EmployeeVO in where condition or in view criteria then execute the query.
  • Expose the method to client interface.
  • Drop DepartmentVO from Data Control into your page then select 'Single Selection' and choice display attribute
    • In behavior tab in property inspector:
      • Add ValueChanged Listener to a bean method (say xBean).
    • In page binding tab:
      • Add new 'attributeValues' binding (Select DepartmentVO for iterator and DepartmentId for attribute) to get selected department id.
      • Add new 'methodAction' binding(select 'GetEmployeeInDepartment" from AM and set parameter '#{bindings.DepartmentId.inputValue}.
  • Drop EmployeeVO from Data Control into your page as form.
  • In valueChange Listner method in xBean, Add the following code:
        this.setValueToEL("#{bindings.DepartmentVO.inputValue}", valueChangeEvent.getNewValue()); //Updates the model and binding layer with new selected department
        BindingContainer bc = BindingContext.getCurrent().getCurrentBindingsEntry();
        OperationBinding oper = bc.getOperationBinding("GetEmployeeInDepartment");
        oper.execute();

ADF BC: LOV For Referrence Attribute From Another Table



Master ------------------------------------------------------------------> Detail
For Example

Master Entity is DepartmentTest and Detail Entity is EmployeeTest
1.       Add two transient attributes to VO of type String one for Code with [MasterCode] Name and the other for Name with [MasterName] e.g. (DepartmentTestCode, DepartmentTestName….)
2.       Make sure in the details tab updatable is always
3.       Make View Accessor to this VO
4.       Use the first transient attribute [MasterCode] and make to its List of Values
·         In configuration tab
§  Make ListDataSource [your view Accessor]
§  View Attribute & List Attribute  [make view attribute (MasterCode,MasterName,Surrogate) and List Attributes (DetailCode, DetailName, Primary key ) respectively ]
For example 
View Attribute
List Attribute
DepartmentTestCode
EmployeeTestCode

DepartmentTestName
EmployeeTestName

DepartmentTestId (Surrogate)
EmployeeTestID (primary key)


·         In UI Hints tab 
§  Default List Type : input text with list of values
§  Selected : select [MasterCode] transient attribute
5.       In VO
·          Select [MasterName] transient attribute and make dependencies based on [MasterCode] transient attribute
·         Select [Surrogate key] and make dependencies based on [MasterCode] transient attribute
6.       In VO
·          Select [MasterName] transient attribute and go to details tab and  write sql query  to not retrieve the first record with null value


Syntax:
SELECT MasterTable.MasterName FROM TableName where MasterTable. primary key = DetailTableEntity.Surrogate Key
Example:
SELECT DepartmentTest.DepartmentTestName FROM HR.DEPARTMENT_TEST  where DepartmentTest. DepartmentTestId = EmployeeTestEntity. DepartmentTestId
·         Select [MasterCode] transient attribute and go to details tab and  write sql query  to not retrieve the first record with null value
Syntax:
SELECT MasterTable.MasterCode FROM TableName where MasterTable. Primary key = DetailTableEntity.Surrogate Key

Example:

SELECT DepartmentTest. DepartmentTestCode FROM HR.DEPARTMENT_TEST where DepartmentTest. DepartmentTestId = EmployeeTestEntity. DepartmentTestId


Or using Groovy Expression by two ways: [optional ]
§  MasterName Groovy write this code :

            oracle.jbo.Key key = new oracle.jbo.Key(DepartmentTestId);
            return DeptVoAcc1.findByKey(key,1)[0].getAttribute("DepartmentTestName");

§   MasterName Groovy follow this steps :

            a. adf.object.applicationModule.getMasterName(DepartmentTestId)
           
           b. Function Application Module
  
 public String getMasterName(Number dno) {
        if (dno == null)
            return null;
        else {
            ViewObject vo = findViewObject("Department1");
            try {
                Row row =
                    vo.findByKey(new Key(new Object[] { new oracle.jbo.domain.Number(dno) }),1)[0];

                if (row != null) {
                    Object name = row.getAttribute("DepartmentTestName");
                    if (name != null)
                        return name.toString();
                    else
                        return null;
                } else
                    return "Specified department does not exists";
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }

        }
    }



7.       In UI
·         Drag and drop [MasterCode] transient attribute with list of values  (ADF LOV Input)
·         Drag and drop [MasterName] transient attribute with input text without label and disable = true
·         Drag and drop [Surrogate key ] with input text and hidden or not dragged
·         Make auto submit of MasterCode = true

If you don't make dependencies in VO you can
·         Make partial dependencies on MasterName  depend on the id of MasterCode
·          Make partial dependencies on Surrogate key  depend on the id of MasterCode




ADF UI: LOV on Non-Reference Key Attribute

Pre-Requirements: Table Employee in HR Schema.

Use-case: Create LOV on FirstName attirbute of all FirstName exist in the same VO 'Employee' and when user select another 'FirstName', Fields updates without change current row binding.

Steps:
  • Create default entity object and view object in tables employee, department
  • In Employee VO:
    • Add two transient attributes 'FirstName_T' and 'EmployeeID_T'
      • Set FirstName_T default Value to expression 'FirstName'
      • Set EmployeeId_T default Value to expression 'EmployeeId'
    • Add new LOV in 'FirstName_T' Attribute.
      • Make accessor to same VO with list attribute 'FirstName_T'.
      • Add list return value
        • EmployeeId_T map to EmployeeId_T
      • In UI Hints tab:
        • Default List:  Input Text with List of Values
        • Display Attributes (FirstName - LastName - EmployeeId)

ADF UI: Change Your Application Locale

faces-config.xml file should have code similar to the following:
<locale-config>
      <default-locale>en</default-locale>
      <supported-locale>ar</supported-locale>
      <supported-locale>ca</supported-locale>
      <supported-locale>cs</supported-locale>
      <supported-locale>da</supported-locale>
      <supported-locale>de</supported-locale>
      <supported-locale>zh_Ch</supported-locale>
 </locale-config>