Oct 16, 2012

ADF Switcher component


The switcher component dynamically decides which facet component should be rendered. It has two properties. The switcher will render the facet matching "facetName"; however, if no such facet exists (or "facetName" is null), and "defaultFacet" has been set, then that facet will be used instead.

Steps:

1.Create VOs based on different tables in the Model Layer:

 

 

2. In View Controller, create a View Page .Drag a Panel Group Layout from the Component Palette onto the page.


3. Drag the Switcher component from the Component Palette into the Panel Group layout.



4.Right Click the af:Switcher component > Insert Inside af:Switcher > Facet




5.Provide a Name for the Facet. Create 2 Facets and provide corresponding names for both.




6.Drag the 'Dept' VO from the Data Controls onto the Facet with name 'Query1' and create a table using the VO.



7.Repeat the Step for 'Emp' VO and create the table in 'Query2' facet. The structure would look as the figure below :




8. Select the Switcher Component and change the DefaultFacet property to 'Query1'



9.In the FacetName property of the Switcher, write #{requestScope.table}



10. Drag a 'Choice' component from the component palette before the Panel group layout .
Provide 2 static values (Facet Names that have been created earlier are taken as Item Values)in the create list tab as shown in the following figure.





11. Change the AutoSubmit property of the Select One Choice to 'true' .

12. Also Provide PartialTrigger property of the Panel Group Layout with the id of the Select One Choice component.
13. Run the Page.











Oct 12, 2012

Association and Association accessor

Relationships between entity object definitions are handled by Oracle ADF associations, which define a relationship between two Oracle ADF entity object definitions based on sets of entity attributes from each.  
Associations map to relationships between single objects in the data source. In the vast majority of cases, these are relationships among tables, views, synonyms, and snapshots in a database.
When the data source is a database, associations often map to foreign key relationships between tables in the database. Although you do not need to actually create a foreign key constraint between tables to create a one-to-one or one-to-many association between the corresponding entity objects, there should at least be an appropriate logical relationship between the tables

1.)Accessor Attributes:-

When you create an association between two entity object definitions, you can elect to add accessor attributes to the source entity object definition, the destination entity object definition, or both.and these accessor attributes function much like other attributes.
Their names can be passed as arguments to EntityImpl.getAttribute(). 
If you generate an entity object class, a getter method for the accessor attributes will be included in the class.
The value of returned by the call to getAttribute() or the getter method depends on the cardinality of the association.

2.)Cardinality:-

Associations can range from simple one-to-many relationships based on foreign keys to complex many-to-many relationships. 
Associations can represent :-
  1. The one-to-many relationship
  2.  The one-to-one relationship
  3. The many-to-many relationship.
The one-to-many and one-to-one relationship work much like foreign key relationships ,i.e., a set of attributes of the source entity object are matched with a set of attributes of the destination entity object definition.
Many-to-many associations are effectively the same as two one-to-many relationships involving the source and destination entity object definitions and a third entity object definition, the intersection.
There are some steps of creating  association:-
 Right click on model and select New option from context menu and select ADF Business Components and then Association option and press ok.
Give the package and Association name and press next.
Now select cardinality and Entity attribute of source and destination entity object and press Add button.
And press next botton.
Now press next 

Press next and Finish.



create a new row in ADF

The 3 different create operations provided by ADF:-
1.)Create:-
This operation opens a slot for a new record in the collection. The new record is added to the collection after the page is submitted.Therefore, if the user abandons the page by navigating away, an empty record is not left orphaned.The new record opened by Create is inserted before the current record in the iterator.

A create operation in the pageDef does the following:
// create a new row for the view object
Row newRow =  viewObject.createRow();
// mark the row as being "initialized", but not yet new
newRow.setNewRowState(Row.STATUS_INITIALIZED);


When we call create and set the status, my adf faces page disables all fields (as if the iterator does not point to the newly created row).

After clicking on Create Button no new row is created in table.








2.)CreateInsert:-
 This operation is the same as Create, except that the new empty record is inserted into the collection as part of the operation.This means that even if the user never submits the page, the row will still be in the collection.

 In addition, if you are using the CreateInsert operation, it performs the additional line of code to insert the row into the row set:
// insert the new row into the view object's default rowset
yourViewObject.insertRow(newRow);

When I call createInsert, my adf faces page reflects the current row as an empty form, when the values are filled out it is commited properly.

 After clicking on CreateInsert Button a new empty row is created.










Note:-Create and CreateInsert, can be a little confusing because they seem to accomplish the same task. The row created by the Create operation is managed as a temporary object by the framework. If the user abandons an
input screen without submitting the new record, the row will simply disappear, leaving the programmer with no clean-up to do. CreateInsert, however, requires clean-up. Although the Create behavior is generally more useful, there are still some circumstances where CreateInsert should be used. Typically, this will be when the side effects of entity object creation are desirable. For example, the create method on the entity object adds information defined as defaults for attributes such as dates and reference numbers. With CreateInsert, this
default information will be visible to the user on the created (blank) record. If the Create operation is used, the defaults will not be set until after the user submits the new record.

3.)CreateWithParams:-
This operation is same as CreateInsert and only difference is that we can assign default values on CreateInsert.

CreateWithParams operation allows us to define parameter to assign it to the new row for some specific attribute.

After clicking on  CreateWithParams button a new row with defalult value of JobId created.










Note:-The ADF BC data control exposes three operations for a view object to create a new row: Create, CreateInsert, and CreateWithParams. The Create operation creates a new row for the collection but doesn’t add it to the iterator. CreateInsert works the same as Create but adds the new row above the current row in the iterator. CreateWithParams works the same as CreateInsert but optionally allows developers to define default values declaratively for the row attributes. The difference between Create and CreateInsert is only relevant if the collection is displayed in a table, not for a form.

Oct 9, 2012

Filtering of data from VO

Sometimes we need to filter View Object data with some condition.

There are different ways of filtering data from View Object.Some of them are:-
1.) setWhereClause:-
        In this method we have to use database table column to add filter.So, we have to get VO and  use
        "setWhereClause" same as  where clause in sql.

      example :-
       Integer empId=4;
       String fName="SCOTT";
       //getting AM
        EmployeesAMImpl am = (EmployeesAMImpl)resolvElDC("EmployeesAMDataControl");
     // getting VO
       ViewObjectImpl emp = am.getEmployee1();
     //filtering data using  setWhereClause
        emp.setWhereClause("employee_id="+empId+" and first_name='"+fName+"'");
        emp.executeQuery();


  In above example employee_id and first_name is database table column and empId and fName is variable to set the value of field.

2.) getFilteredRows :- 
      In this method we have to use VO  column to add filter.So, we have to get VO and  use
      "getFilteredRows" .This method is use to filter for only one column. Method  getFilteredRows return type is Row[].

example:-
        Integer empId=4;
       //getting AM
        EmployeesAMImpl am = (EmployeesAMImpl)resolvElDC("EmployeesAMDataControl");
     // getting VO
       ViewObjectImpl emp = am.getEmployee1();
     //filtering data using  getFilteredRows. As this method returns Row[] type ,so we can use thats row //for our purpose.
Row[] Emprow= emp.getFilteredRows("EmployeeId", empId);



In above example EmployeeId is VO column name and empId  is variable to set the value of field.

3.) RowQualifier:-

In this method we have to use VO  column to add filter.So, we have to get VO and  use    "setWhereClause" method of RowQualifier and  "getFilteredRows"  method of VO for filtering .This method is use to filter on the basis of 1 or more columns.Method  setWhereClause is used to filter data and method  getFilteredRows return type is Row[] after filtering.

example:-
       Integer empId=4;        String fName="SCOTT";
       //getting AM
        EmployeesAMImpl am = (EmployeesAMImpl)resolvElDC("EmployeesAMDataControl");
     // getting VO
       ViewObjectImpl emp = am.getEmployee1();
     // creating RowQualifier
        RowQualifier rowQualifier = new RowQualifier(emp);
     // filtering data using method setWhereClause
        rowQualifier.setWhereClause("EmployeeId="+empId+" AND FirstName="+fName);
   // use method getFilteredRows to return Row[] type after filter.
        Row[] filteredRows = emp.getFilteredRows(rowQualifier);

In above example EmployeeId and FirstName are VO column name and empId and fName are variable to set the value of field.


Note:-  setWhereClause is use to filter data using database column.
            getFilteredRows is use to filter data using VO column name but only one column is use to      filtering of data using this method.
           RowQualifier is use to filter data using VO column name but one or more than one column is use to filtering of data using this method.We have to use both use    "setWhereClause" method of RowQualifier and  "getFilteredRows" method of VO for your purpose.