Tuesday, December 31, 2013

ADF resource bundles

When you add any UI hints the project level resource bundles are getting created.We can access the resource bundle properties from the project properties dialog

Custom settings are not recorded with the project and cannot be shared with other users who use this project.You can note the basic configuration preferences options above.Resource bundle types are Properties Bundle which is the default option ,List resource bundle and Xliff resource bundel

Properties Resource bundle 

Create a new .properties file from the New Gallery option.Add name value pair for the property file.We can add the resource bundle from the "Bundle Search" tab.
From the UI hints section you can search fro the new Properties Bundle created.

List Resource Bundle 

Create a java class

import java.util.ListResourceBundle;

public class TestListResBundle  extends ListResourceBundle {

    @Override
    protected Object[][] getContents() {
        // TODO Implement this method
        return contents;
    }
    static final Object[][] contents = {
          {"key1", "Cabinet {0} contains {1} folders."},
          {"key2", "Folder {0} contains " +
                    "{1,choice,0#no files|1#one file|1<{1,number,integer} files}."},
          {"key3", "Folder \'{0}\' is empty."},                     
          {"key4", "File \"My Stuff\" deleted."},                    
          {"key5", "Added {0,number} files."},            
          {"key6", "Testr"},
          {"key7", "No files were removed while processing " +
                         "current folder."}
      };

    }
Add the resource bundle to the project 
Select the resource bundle from the list resource bundle 

Xliff Resource bundle 

Create a .xlf file 
<?xml version="1.0" encoding="windows-1252" ?>
<xliff version="1.1" xmlns="urn:oasis:names:tc:xliff:document:1.1">
  <file source-language="en" original="myResources" datatype="xml">
    <body>
      <trans-unit id="NAME">
        <source>Name</source>
        <target/>
        <note>Name of employee</note>
      </trans-unit>
      <trans-unit id="HOME_ADDRESS">
        <source>Home Address</source>
        <target/>
        <note>Adress of employee</note>
      </trans-unit>
      <trans-unit id="OFFICE_ADDRESS">
        <source>Office Address</source>
        <target/>
        <note>Office building </note>
      </trans-unit>
    </body>
  </file>
</xliff>
Add xlf resource bundle as other resource bundles.Select the resource bundle for UI hints properties from xlf resource bundle 

Format Mask in ADF UI hints

Format mask requires for data type like date.
C:\\JDeveloper\system12.1.2.0.40.66.68\o.BC4J\formatinfo.xml  file stores the formats of datatypes.
Sample formatter is here
<DOMAIN CLASS="java.sql.Timestamp">
      <FORMATTER name="Simple Date" class="oracle.jbo.format.DefaultDateFormatter">
         <FORMAT text="yyyy-MM-dd" />
         <FORMAT text="hh:mm:ss"  />
         <FORMAT text="yyyy-MM-dd G 'at' hh:mm:ss"  />
         <FORMAT text="EEE, MMM d, ''yy"  />
         <FORMAT text="dd-MM-yy" />
         <FORMAT text="dd-MMM-yyyy" />
         <FORMAT text="dd/MMM/yyyy" />
         <FORMAT text="MM/dd/yyyy" />
      </FORMATTER>
   </DOMAIN>
Custom formatters can be created by extending oracle.jbo.format.Formatter class.

Monday, December 30, 2013

ADF Defining Property Sets

ADF property sets are collection of properties and each property is a name value pair.Property set is used in the control hints and messages.Property sets used with entity objects and their attributes , view objects and their attributes and in the application modules
Property set can be create from the new Gallery.Give a property set name and package and click ok.Applying property set to the entity object is as shown below
Apply the property set in the attribute level as below

ADF Creating entity diagrams

From the new gallery create entity diagram
Drag and drop entity objects to it

ADF creating associations

Associations in the entity level can be manually created as below
Shown above are the two tables created to demonstrate association.Create entity objects for both the table using create entity object wizard. Create an association using the wizard
Add the association created as below
Edit association query 


The final screen 


Effective dated entity objects

- Effective dated tables are used to provide a view into the data specific to a time
- Effective dated entity objects can be created as below
From the entitiy object General tab change the Effective Date type to "Effective Dated".
Click on the edit icon
If the effective date sequence and flag is not selected , the effective date is for one day.When we specify the effective dated property for the entity object a transient attribute SysEffectiveDate is created.We need to specify a start date and end date attributes defined in the entity object.Effective date sequence stores the sequence stores the sequence of changes.Effective date sequence flag sets the most recent change in the sequence.

Thursday, December 19, 2013

Setting Default value of VO attribute using Groovy expression


Refer the blog http://suneesh-adf.blogspot.in/2013/12/setting-default-value-of-eo-attribute.html for the db design and BC objects.

Create the UserDetailVOImpl class and add the method :
              public String getHello() {
         return " Hello Suneesh";

    }

Provide the groovy expression to the default value of the transient attribute 
Run the BC tester and add new row.You can see "Hello Suneesh" defaulted.

Setting default value of EO Attribute using Groovy

Create user and user details table as below
Create a BC structure as below 

Generate Impl classes for UserTblEO and add the following method to it 
    public String getName(String name) {
        return "Hello "+name;
    }
Provide the default value of login name expressio as above 
Run the BC tester for LoginAM and create a new row .You can see login name defaulted.



ADF Groovy basic notes

Some of the properties of groovy scripting language

- Groovy is a scripting language having java like syntax
- Groovy is executed at run time
 Can be used in Entity and View objects in attribute validators(Entity Objects),attribute default values( Entity and View),bind variable default values ( View) place holder for error messages (EO validation rules)
- Define script expression validator or Compare validator 
- Error message tokens can be defined for handling validation failures 
- Conditional execution of validatiors are possible 
- Default value of bind variable in view object can be defined using groovy expression 
- Default value of view criteria 
- Default value and optional re-calculation condition for EO
- Value of transient for EO and VO 


Referencing Buisiness components objects in Groovy expression
Top level object is "adf" . Accessible ADF objects throgh groovy are 
- adf.context - Reference to ADFContext 
- adf.object - Equivalent to this operator in java.
- Entity Objects attributes - Reference methods and attributes of EntityImpl class.
- Entity Objects script validator rules - Attributes and method of ViewImpl class.
- View Object attributes 
- Bind Variable in view Object 
- Bind variable in view accessors 
- Transient attributes 
- adf.error 
- adf.userSession 
- adf.currentDate 
- adf.currentDateTime 
- Referencing custom buisiness components methods and attributes 
eg. Sal*12 - annualsalary .
PromotionDate>HireDate 

Method of entity class in validation rule.For validators use source keyword
eg. source.getDefaultSalaryForGrade()

- newValue - Attribute value being set 
-oldValue - current value of attribute being set 

if(Job=’SALESMAN’)
{
 return newValue<source.getMaxSalaryForGrade(Job)
}

Manipulating business component attribute values in a groovy expression
RowSet Objects
-          rowSetAttr.sum(GroovyExpr)
-          rowSetAttr.count(GroovyExpr)
-          rowSetAttr.avg(GroovyExpr)
-          rowSetAttr.min(GroovyExpr)
-          rowSetAttr.max(GroovyExpr)
EmployeesInDept.sum(“Sal+adf.object.getBenefitsValue(Job)”)

Friday, December 6, 2013

ADF client interfaces

Only the services available to the client are

1) Application Module through interface ApplicationModule
2) View Objects through the interface ViewObject
3) View Row object through the interface Row

Entity Objects are not exposed to the clients .

ADF - Basic data types

ADF business packages for datatypes are oracle.jbo.domain and oracle.ord.im .ADF data types are optimized for better performance.In two case we need to use java datatypes - java.lang.String and java.math.BigDecimal

Basic data types are as below :
oracle.jbo.domain.Number
oracle.jbo.domain.Date
oracle.jbo.domain.DBSequence
oracle.jbo.domain.RowID
oracle.jbo.domain.Timestamp - Time stamp object
oracle.jbo.domain.TimestampTZ - For timestamp based on timezone
oracle.jbo.domain.TimestampLTZ- Local timezone based
oracle.jbo.domain.BFileDomain - Binary file object
oracle.jbo.domain.BlobDomain - BLOB
oracle.jbo.domain.ClobDomain - CLOB

oracle.ord.im.OrdImageDomain
oracle.ord.im.OrdAudioDomain
oracle.ord.im.OrdVedioDomain
oracle.ord.im.OrdDocDomain

oracle.jbo.domain.Struct
oracle.jbo.domain.Array



Overview of ADF business component implementation



- Standard Java and XML based implementation
- Metadata driven robust code
- Source code support for debugging in ADF declarative debugger
- Application server and database independence
- Java Enterprise Edition design pattern support . Business component implements all standard design patterns
- Source code organization through packages : oracle.jbo package for interfaces and oracle.jbo.server package for implementation classes.

ADF Active Data Model Overview

 - ADF maintained active data model of row set
- Data model defines business objects specific to your application
-  Row set contains the data
- UI and data model are synchronized
- UI updates the rowset of Application Module's data model
- No CRUD operation directly. CRUD operations are done through view objects
- ADF decoratively binding UI components with data model
- Data appears in UI without re-querying the database. Changes in the database reflects in the UI.
- Active data model supports custom code through custom methods in Application Module



Wednesday, December 4, 2013

ADF Choosing SQL platform,Connection and Datatype Map

First time when you create the business component you will see the window below.
You can create or select connection through the above interface.SQL platform option support Oracle,DB2 or any other SQL92 complaint databases.

Datatype Map : The default option is Java Extended for oracle. Oracle Domains data type map is getting used for applications which do not use adf faces.Data types are created in oracle.jbo.domain packages.java.math.BigDecimal extends java.math.Number for numeric data in Java Extended For Oracle data type map and oracle.jbo.domain.Number in Oracle Domain map.All new fusion applications should use Java Extended for Oracle map and other other one is basically provided for backward compatibility.We cannot change the map once created.
SQL platform can be overridden through adf-config.xml file

   

ADF Buisiness components

In ADF using business components developers no need to write the infrastructure code
  a) Connection to database
  b) Retrieval of data from the database
  c) Locking mechanism of db records
  d) Transaction management

All above actions are handled by the ADF framework.Also ADF supports declarative development and reuse of the business logic through multiple sql based views.

Some of the high level features of business components are

- Simplify data access
- Enforcement of business domain validation  and business logic
- Supporting sophisticated UIs with multipage units of work
- Implementing high performance service oriented architecture
- Streamlining application customization

Following are the main components of business components

- Entity Objects
 Entity objects represents rows in database .Entity objects ensure business logic are consistently enforced.It supports associations to other entity objects
- View Layer
Represents a SQL query.Enables re-use of business logic through multiple sql based views.

- Application Modules
Is a transnational component that UI client use to work with application data. Application Module holds view objects and other custom methods.

Sunday, December 1, 2013

Using ADF Faces Dialog framework

-          Use ADF faces dialog framework to create dialog in application doesn't uses ADF controller and task flows 
-          Enables display a page or series of pages in a separate browser windows

-          If application uses fusion technology you should use task flows to create popups 
Create a control flow case and view activity in adfc-config.xml file as below.

Look at the dialog:syntax used.

Code for dia_view1.jspx 

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <f:view>
        <af:document title="dia_view1.jspx" id="d1">
            <af:form id="f1">
                <af:button text="button 1" id="b1" action="dialog:toView2" useWindow="true" windowModalityType="applicationModal" windowHeight="200"
                           windowWidth="300" launchListener="#{pageFlowScope.DialogBackingbean.launchListener}"
                           returnListener="#{pageFlowScope.DialogBackingbean.dialogReturnListener}"/>
            </af:form>
        </af:document>
    </f:view>
</jsp:root>

The adf command button uses the properties highlighted .Also look into the launch listener and return Listener code.

dia_view2.jspx 


<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <f:view>
        <af:document title="dia_view2.jspx" id="d1">
            <af:outputText value="First Name : #{pageFlowScope.username}" id="ot1"/>
            <af:form id="f1">
                <af:button text="Close" id="b1" immediate="true">
                    <af:returnActionListener/>
                </af:button>
                <af:button text="Cancel " id="b2" actionListener="#{pageFlowScope.DialogBackingbean.testAction}"/>
            </af:form>
        </af:document>
    </f:view>
</jsp:root>

A close and cancel button is provided to demonstrate both ways of closing the popup.

The DialogBackingbean java bean code below.

package view.test;

import javax.faces.event.ActionEvent;

import oracle.adf.view.rich.component.rich.output.RichOutputText;
import oracle.adf.view.rich.context.AdfFacesContext;

import org.apache.myfaces.trinidad.event.LaunchEvent;
import org.apache.myfaces.trinidad.event.ReturnEvent;

public class DialogBackingbean {
    private RichOutputText outTextBind;

    public DialogBackingbean() {
    }

    public void listenerMethod(ReturnEvent returnEvent) {
        System.out.println("Return Listener..");
        // AdfFacesContext.getCurrentInstance().getPageFlowScope().put("testValue", "Testing");
        String retVal = (String) AdfFacesContext.getCurrentInstance().getPageFlowScope().get("retVal");
        System.out.println(retVal);

        this.getOutTextBind().setValue(retVal);
        AdfFacesContext.getCurrentInstance().addPartialTarget(this.getOutTextBind());
    }

    public void setOutTextBind(RichOutputText outTextBind) {
        this.outTextBind = outTextBind;
    }

    public RichOutputText getOutTextBind() {
        return outTextBind;
    }

    public void testAction(ActionEvent actionEvent) {
        User user = new User();
        user.setUsername("SuneeshVR");
        AdfFacesContext.getCurrentInstance().returnFromDialog(user, null);
    }

    public void launchListener(LaunchEvent launchEvent) {
        System.out.println(" Launch Listener");
       // Using the below code we can pass the parameter to the popup page.
        launchEvent.getDialogParameters().put("username", "suneesh");
    }

    public void dialogReturnListener(ReturnEvent returnEvent) {
      System.out.println("Inside dialog ret listener..");
     
      User user =(User)returnEvent.getReturnValue();
      System.out.println(user.getUsername());
    }
}

User bean is a simple java bean having the username property.