Showing posts with label ADF Tutorial. Show all posts
Showing posts with label ADF Tutorial. Show all posts

Thursday, February 28, 2013

Using af:Iterator with master/detail to display data in custom layouts


Below example shows steps to use af:iterator in a master/detail senario

1. Create a ADF BC components(EO, VO, AM) with the viewlink for master/detail.

2. Drag and drop the master on to the page as tree table.

3. Create the first iterator to access the master collection via above tree binding, create the second iterator via the accessor binding. (Accessor name is present in the binding defination also in the view link defination)

4. You can create different combination of layout with this approach.



5. You can download the complete example here.

Saturday, February 2, 2013

ADF: Auditing Changes to the same Database table. (recording history of changes)


Auditing the changes to a database record can be done in multiple ways. One of the ways is to store the changed record and the original record in the same table. A column would differentiate the active record from the audit record.

This can be easily acheived in ADF BC. Below example demonstrates the steps needed.

1. Data Model.
ACTIVE - indicates the if the record is a current record or a audit row.
ACTIVE_ID - stores the original id

 2. Create ADF BC EO/VO as below. Configure the EntityObject with history columns, primary key genration logic etc.



3. Create a subclass of EntityImpl and override doDML(). The logic below captures Update operation and splits the row into two. The current row contains the updated values and a new row contains the old values. Delete operation is captured and propagated as update operation with setting active flag to "N".



4. Configure the CustAuditEO to use the above base class.

5. Create a View Criteria to filter active records.



6. Create a view link within the same view object, joining on Id and AuditId



7. Expose the View Object Instances in AM Data Model as below. And configure the base view object to show only active records.



8. Run the UI project. Create a new row. save the changes. Update the row and save the changes. Click the view history button to see the complete audit trail of changes.


You can download the example here.

Sunday, January 6, 2013

ADF: Default Detail, Only One Detail Row can have the default flag set



     1. Create ADF BC components and setup the AM Datamodel for master detail. From the data control panel drop the detail as Master Form and Detail Table.



      2.       Drop the Preferred Flas as a Single Selection Column, Boolean Checkbox on the detail table. Choose the selected and unselected values for the checkbox.







       3.       Edit the properties of the Checkbox, add auto submit to true and set partial trigger on the detail table to the checkbox. Add a value change listener and bind it to a bean proeperty.


        4.       Add logic in value change listener to update all other rows when a new default row is selected.



       5.       Run the application and select a new default row, you can observe that the other default row already selected is cleared.


You can download the complete application here.

ADF: Simple steps create a Shared Application Module instance to improve performance


 Below steps show how to create define a Application Module instance and share it across application.

      1.       Build ADF BC for HR tables Employees, Departments. Create two application Modules EmployeeAM and CommonAM.


        2.       Add Departments View Object instance in CommonAM Data Model.



         3.       Add Employees View Object instance in EmployeeAM Data Model.




        4.       Go to Model project properties -> Business Components -> Application Module instances. Here you’ll see option to add an Application Module instance as shared across Application or Session.




       5.       Now you’ll be able to see the Shared Application Module Instance when declaring view accessors for a view object.



      6.       If you create two different connection pools for each AM, and assign them accordingly in AM configurations.



      7.       Open two separate page in two different browsers you can observe that the Shared Application Module uses a single database connection.


 You can download the complete application here.

      8.       Using this option provides following performance benefits
·         Improved runtime performance.
·         Numbers of queries executed against database are reduced.
·         Memory utilization for storing view object rows is reduced.

Saturday, December 29, 2012

ADF Data Model – Detail with Multiple Masters



      1.       In this Example, a Many to Many Relationship in the database is captured in AM Data Model as Detail with Multiple masters.
      2.       Data Model shows a MMD_PRODUCT, MMD_STORE have a many to many relationship using MMD_INVENTORY.
        3.       Create ADF BC components for the above tables.



        4.       In AM Data Model, add Product view instance and Inventory view instance as a child.





      5.       Next step is the important step to capture the Detail with Multiple masters. Add Store view instance and Inventory view instance as a child. When adding a view instance with the same name as an existing instance, you will be given an option to use the existing instance. Select Yes.






      6.       As you can observe now Inventory View Instance is a child of both Product and Inventory.
      7.       You can easily create a Master Master Detail relationship in ADF page as below. When you change the selection in either Product (Master) or Store (Master) the Inventory (Detail) gets updated.


You can download the complete example here.


ADF Global Style Selectors, AFStretchWidth and others

ADF Faces provides a easy way to style components using Skinning.

Apart from skinning components, Global Style Selectors help with layout of the components. AFStretchWidth is one of the most frequently used global style class used to stretch a component horizontally.

For a complete list of you can browse through Oracle Documentation here.

Sunday, December 16, 2012

ADF Query Panel with CheckBox (Boolean search attribute)


In database the Boolean values in a column are usally stored as Y and N. This example shows how to search such columns using CheckBox.

      1.       Add a new attribute in view object. Select Mapped to Column or SQL, unselect Selected in Query, provide the alias and SQL expression DECODE(ACTIVE,’Y’,1,’N’,null).




         2.       In the attribute control hints select control type as Check Box



       3.       In query tab create view criteria to use as search panel.


       4.       From data controls, drag and drop the view criteria as ADF Query panel with table.


        5.       Run the page and use the checkbox to search for active and inactive users.


      6.       You can also provide a default value for the checkbox in viewcriteria.
    
      7.       You can download the complete example here.

Master Form Detail SelectManyChoice


In my earlier post I showed an example to use SelectManyShuttle as a detail in Master-Detail pattern, you can also use other multi select components as details.

Below shows SelectManyChoice being used as the detail.




All you need to do is in step 6 (from post) just update the page xml as below instead.


Saturday, December 15, 2012

Master Form Detail Multi Select Shuttle Pattern




Below Example demonstrates having Master Form with detail as Multi Select Component.

      1.       Data Model. Each Employee can have one or more skills. All possible skills are stored in SKILLS table. Each employee skills are stored in EMPLOYEE_SKILL.

This example user Oracle default HR Schema, additional tables can be created from SelectManyShuttle\DB\database\XE\CreateSchema.sql. File is available in the application zip.

      2.       Setup the Application Module Data Model as below.




      3.       From the Data Control Panel drag and drop the Employee -> EmployeeSkill as ADF Master Form, Detail Table as below



        4.       Create a request scope Bean and add setter and getter method as below



      5.       Now to create a List of all skills add a Table binding. Go to page bindings tab, click the add under bindings. Select tree. Add a new root data source. Select Skills view object. Select the Add Icon and Add Rule. Select SkillId, SkillName as Display attributes.




       6.       Delete the skills table, and a SelectMultiShuttle component. Bind the value to bean property. To dynamically create a selectItem list, we’ll use a forEach loop.


      7.       For the current employee the available skills should get defaulted to employee skills from EMPLOYEE_SKILL table, accordingly when the items are updated the rows need to get added/removed accordingly. We’ll add the logic in setters and getters to achieve this.


        8.       Download the complete example here.

ADF View Object - View Criteria Row with SQL Literal

View Criteria provides an ability to decoratively add a where clause fragment to view object. 

Jdeveloper GUI by default provides option to declare a view criteria items value either as a 
  1. Literal 
  2. Bind Variable. 
There is also support for adding a literal that would be treated as a 
  1. SQL fragment
Below steps show how to configure
      1.       Create View Criteria, Add a view criteria item, Select operator as HireDate, Operator as Between and Operand as Literal

       2.       Go to the Source Tab of the View Object and add an IsSqlFragment attribute with value true in view criteria item value as below.



          3.       From the View Criteria Editor provide values sysdate-3650 and sysdate


       4.       Click on Test button to validate the Query


       5.       To Test the Apply the View Criteria in Application Module Data Model.


        6.       Run The Query from SQL WorkSheet and AM tester to compare the results.


       7.       The Sample application attached here. Let me know if you have any questions.
       8.       You can also use the same logic for other operators; ViewCriteriaRow also supports the IsSqlFragment attribute. Here is an example.
Related Posts Plugin for WordPress, Blogger...