Continuing the ADF Insider series, ADF Insider Essentials documents essential skills, tips and techniques you will need for building an application. Each ADF Insider Essentials presents not only a solution to a common ADF development use case, but can be used as way of building your own skills by challenging you to build your own solution. You can then compare your efforts against those of an ADF expert explaining how they solved the problem. Each task is rated, using this icon , with a difficutly of one to five. One being a task that should have a simple and quick to implement solution, whereas a task with a rating of five would suggest a solution that requires a higher level of understanding and utilization of the framework and its features.
Programmatically iterating through rows of a view object Task: How would you programmatically iterate through the rows of a view object to perform an action on each row. For example, for a selected department, you want to give a fixed pay rise to every employee in that department so you want to programmatically access each employee row and and update their salary. Hint: This functionality needs to be applied to a single Departments Row but across many Employee Rows. The ViewRowImpl class represents a row in a view object and a RowSet represent the collection of these queried employee rows. Solution: Click here to watch Grant Ronald walk you through a solution.
Building a dependent list of values Task: You would like to limit the choices in a drop down list depending on some other data. For example, a department's location is based on a country and a city. You want to ensure that the drop down list of cities only shows cities in the currently selected country. Hint: The HR schema defines a Departments table, cities are defined in the Locations table and countries are defined in the Countries table. You will need to ensure your view object contains the required attributes. You can use a model driven list of values to define the drop down list for DepartmentsVO.LocationId. A view criteria is a good way of filtering a view object (on which a model driven list of values is based) and it can be parameterised so you can pass the value of country which will filter the model driven list of values. Solution: Click here to watch Grant Ronald walk you through a solution.
Implementing Sequences in an ADF Application Task: When creating a new record (such as an employee or department) you are required to assign a unique value to the primary key attribute. So, in the Departments table this would be Deptno and in the Employees table this would be Empno. These values should be assigned from a database sequence. Hint: There are two possible ways to achieve this. The first is when a new Department row is created in the entity object, you can read a database sequence (SequenceImpl) and assign a value. The other option (for Employees.Empno) is to assign the sequence in a database trigger and then allow the framework to automatically refresh the attribute with the assigned value. Solution: Click here to watch Grant Ronald walk you through a solution.
Extending ADF Framework Security with Resource Permissions Task: Using ADF Security, you would like to set permissions that some users can only edit data when the row is being inserted. Once inserted, users with this permission cannot update the row. Hint: You will need to create a new resource type (e.g. insert) and extend the EntityImpl to handle this new case by checking ResourcePermission. Solution: Click here to watch Frank Nimphius walk you through a solution.
Programmatically access a view criteria Task: How would you programmatically enable a view criteria from the UI. For the employees view object you would like to set up two view criteria to filter based on DeptId and JobId. You should be able to apply each of the view criteria independently, or together and also to remove an applied view criteria. All this should be initiated from a UI action such as a button or task flow method activity. Hint: You can expose client methods in the View Row Impl to programmatically access a ViewCriteria object. Solution: Click here to watch Grant Ronald walk you through a solution.
Setting a Row as non editable based on a value July 2011 Task: For the orders table in the OE schema, if an order is closed (order_status) then the data for that record should not be editable. Hint: There is a framework method which checks to see if an attribute is updateable. You need to override this to check the order status. Solution: Click here to watch Grant Ronald walk you through a solution.
ADF BC Model Driven LOV Switcher Task: In Oracle ADF Business Components, developers can define model driven list-of-values for consistent data lists and UI rendering at runtime. In addition, model driven list-of-values can be configured to be dependent so they present a master-detail relationship of the list data. A not so well known feature of model driven list-of-values is that the LOV definition can be switched at runtime, which ususally is triggered by data in a related view object attribute. This video shows an example of a list-of-values that changes its data list from credit card types to currencies dependent on the selected payment mode, which can be CREDIT or CASH. Hint: There is a framework method which checks to see if an attribute is updateable. You need to override this to check the order status. Solution: Click here to watch Frank Nimphius walk you through a solution.
Referencing a default value from an attribute in a different EO Task: How would you default an attribute of one entity to the value of another? For example, you want to set the default price of a product for new order items, where the order item and product attributes are defined in different entities. Hint: Call the setPrice() method from the Item entity and set the value to the product price for a particular product id. Solution: Click here to watch Jeff Gallus walk you through a solution.
Implementing a total Task: You want to display a sum of an attribute, such as a total of salaries in a department. This total is not stored in the database as a persistent attribute. Hint: You can use a groovy expression to calculate the sum of an attribute in a transient attribute. Solution: Click here to watch Dede Morton walk you through a solution.
Building a test client for testing ADF Business Components Task: How do you ensure that a query returns expected results for a View Object that uses bind variables and view criteria? Hint: Use the ADF Model tester or a java test client to programmatically test a View Object. Solution: Click here to watch Jeff Gallus walk you through a solution.
Basing ADF Business Component View Objects on more than one Entity Object Task: Tables are littered with foreign keys that have little meaning to users. Often we want to show fields from other tables with more meaningful values to the user, and, if the user changes the foreign key the lookup values are instantly changed. Your challenge is to setup such a solution with ADF Business Component View Objects where the View Object is based on more than one Entity Object: A updatable Entity Object and a reference lookup Entity Object. Bonus points are awarded for consructing a JSF page where the foreign key value is changed and the lookup fields are automatically update. Hint: For the ADF BC View Object you will require two Entity Objects related via an Entity Object Association. For the JSF page you will need to make use of the AutoSubmit and PartialTrigger properties. Solution: Click here to watch Chris Muir walk you through a solution.
Retrieving the previous value of an ADF BC attribute Task: Sometimes we will have a requirement to show the previous value of an ADF BC attribute, or even create a business rule that needs to compare an old and new value for an attribute. Your challenge, using the HR schema Employee table, is to a) create a transient attribute in an Employees Entity Object to show the previous value of the Salary attribute before it was changed by the user and b) create a "Script expression" (a.k.a. Groovy expression) attribute level business rule that enforces a new value for a salary that is not greater than 10 percent of the old value. Hint: The EntityImpl provides a method getPostedAttribute for returning the old value of another attribute b) While you could use get PostedAttribute in the Groovy expression, Groovy support in ADF provides two implicit objects at attribute level to return the old and new value of the current attribute which you can use instead. Solution: Click here to watch Chris Muir walk you through a solution.
Accessing ADF Binding Layer from Java Task: You have a form for inputing a new employee and a table showing all employees. On pressing a button you want to do the following: commit the new employee record, filter the table of employees to show employees who are in the department of the employee you just added, and you want to refresh the table to show only those employees. Hint: Your code should be in a single method in a backing bean. You need to access an action binding for the commit and an action binding to call ExecuteWithParams to execute a where clause or view criteria to filter the data. Remember, you will need to pass in the departmentID of the newly created employee. Finally you need to fresh the table UI component. Solution: Click here to watch Frank Nimphius walk you through a solution.
Synchronizing a Tree Control with Detail Data Task: You have a tree control showing Customers by Country. You also have a tree control showing Customers by Sales Rep. In either of these tree controls, if you select a customer, you should see the details for that customer in a form. Hint: This is not a master detail data model; CountriesVO, CustomersVO and SalesRepVO should be top-level data collections in your application module. Accessors between the view objects allow the tree control to build the appropriate hierarchy. When you build the tree control you should be able to define that the CustomersVO instance should be refreshed when the node in the tree is selected. Solution: Click here to watch Grant Ronald walk you through a solution.
How-to populate an af:selectOneChoice component from a different DataControl than the one used to update the model Task: You create an editable table or form and then change a field from inputText to selectOneChoice. The lov list shall be populated by a Data Control different from the one that is used to update the table or form. Hint: Create a form from a collection in a Data Control. Delete a form field and drag it back in from the Data Control palette. Choose selectOneChoice and define a dynamic list pointing to a collection in the other Data Control. Solution: Click here to watch Frank Nimphius walk you through a solution.
Passing Data Within A Task Flow Task: You have a task flow consisting of a search page, a method call to perform the search, and a results page to show the result of the search. So for example, you enter a credit limit value in the search page, this value is read by the method activity to filter all customers with a credit limit greater that this value. You then display the result in the final page which also includes the label/prompt "Customers with Credit Limit greater than" <value>. Hint: You could use a memory scoped variable to hold the value to be accessed by the various activities in the taskflow. So for example, on pressing a button you could set the value of the memory scoped variable (SetPropertyListener), and you would refer to this variable in the method call and in the label/prompt. Solution: Click here to watch Grant Ronald walk you through a solution.
Dynamic UI Layout using the ADF Faces Switcher Component Task: Build a page containing a panel inside which you want to display two different styles of UI components that you can switch between by selecting a menu option or pressing a button. Hint: You can use af:switcher to switch between different UI components. Solution: Click here to watch Grant Ronald walk you through a solution.
Storing Different Values to those Displayed Using a selectOneRadio Task: In your database, for example Orders.OrderFilled, you are storing a single character value Y or N. However, when exposing that attribute to the user as a radio button you would like to display "Yes" and "No" as the data values while still storing Y and N in the data model Hint: Using ADF Business Components model driven list of values and a read only view object to store the display and data values, you should be able to then easily drag and drop the attribute onto the page as a selectOneRadio Solution: Click here to watch Grant Ronald walk you through the solution.
Using af:iterator to Dynamically Render an Image Task: Depending on the value in a field, you would like to "stamp" out an image that number of times. For example, if a customer has a rating 1-5 then you would like to display a star that number of times. So a customer with a rating of 3 would display 3 stars to indicate their rating. Hint: An af:iterator component can take an array list as its value. The number of elements in that array will define how many times the iterator will stamp out. For a more advanced example, the array could also define which image should be stamped out. Solution: Click here to watch Grant Ronald walk you through a solution.
How-to delete node(s) in Oracle ADF bound ADF Faces hierarchical trees Task: You determine the selected tree nodes and delete them from an action exposed on the tree context menu. You will create a tree, define a context menu, and create a managed bean action to handle the tree node(s) delete operation. Hint: Create a menu component in the tree's menu facet followed by creating a menu item. Point the menu item ActionListener to a managed bean. Reference the tree component from a JSF component binding reference to the managed bean. Get the selected RowKeys and iterate over them to delete the node. Solution: Click here to watch Frank Nimphius walk you through a solution.
Strategy for creating page templates with global button functionality Task: You build a page template that contains a button bar for Create, Insert, Delete, Cancel and Help functionality. The buttons should execute functionality that is specific to the page that uses the template. Hint: Page templates don't have method attributes, so you need to think out of the box. Knowledge about ADF Libraries and how managed beans can be deployed and configured in a JAR file guides you to the solution. Solution: Click here to watch Frank Nimphius walk you through a solution.
Programmatic Partial Page Refresh Task: You have created an Emp table and to edit an employee you have a task flow inside a popup which displays an Emp form. However, on updating an employee, the table does not reflect the changes you have made. Hint: You will need to write code in a managed bean that will, on returning from the button press, will get the current ADFFacesContext and add a partial refresh to the table. Solution: Click here to watch Grant Ronald walk you through a solution.
Customizing the ADF Search Form Initial Rendering and Query Behavior Task: How would you initially render the ADF search form in advanced mode and then change the query behavior to case insensitive. As an extra goody, How can you use a custom view criteria with ADF table filters. Hint: Create an ADF search form rendering in advanced mode that performs case insensitive queries by first creating a custom View Criteria followed by defining UI hints and then create the search form from the custom View Criteria. Solution: Click here to watch Frank Nimphius walk you through a solution.
Undo ADF table selection on validation error Task: What do you do if uncommitted data exists when users change the row currency of a table. If uncommitted data exists, an alert is shown to remind the user to commit the changes before selecting another row in a table. If data change validation succeeds, the system sets the new table row as the current row in the underlying binding layer. Though the example uses data commit as the validation exit criteria, it can be any Java accessible condition that determines whether the row selection needs to be undone or not. Your task is to create an editable ADF table that restores the previous selected table row if uncommitted data exists upon table row selection. Hint: Override the ADF Faces table SelectionListener, get the old selected RowKeySet from the selection event, read the transaction state from the controller context, and make the selected table row current in case uncommitted data is not found. Solution: Click here to watch Frank Nimphius walk you through a solution.
How to implement logging in an ADF application Task: You're building an ADF application, and you want to understand more about how the ADF framework functions at runtime. You want more comprehensive debugging capabilities and you want to use the advanced features of JDeveloper's debugger to help you debug issues. You should therefore request, configure and install the ADF source code. Hint: You can import the ADF source code for debugging purposes, and enable diagnostic logging to help you debug ADF applications more efficiently. Solution: Click here to watch Lynn Munsinger Brown explain how to request and install the ADF source code.
Debugging task flows and memory scope Task: You're hitting a NullPointerException when navigating through rows in your ADF application - what do you do? Hint: Use the ADF Task Flow debugger to determine where the error is occurring and what code is causing the exception Solution: Click here to watch Lynn Munsinger Brown explain how to debug task flow memory scope issues.
General ADF Techniques
Deploying reusable components Task: You want to distribute parts of an application for reuse. For example, you want to ensure all UI developers use your organization's page template and base data model. Hint: You can use an ADF Library to deploy reusable components. Solution: Click here to watch Dede Morton walk you through a solution.
ojdeploy ADF Build Utility Task: Beginner ADF developers are familiar with how to deploy ADF applications via the IDE but what about if you had to automate the process? Can you build your ADF applications via the command line ojdeploy utility provided by Oracle, or for bonus points using ojdeploy via Apache Ant. Hint: JDeveloper's online help shows you the syntax to invoke ojdeploy via the command line, while scripts for ojdeploy and Ant can be created via the New Gallery. Solution: Click here to watch Chris Muir walk you through a solution.
Configuring your ADF Mobile development environment for Android Task: You want to deploy your ADF Mobile application on Android and need to test it in the Android emulator and on your own devices. Hint: Getting the ADF Mobile extension for JDeveloper 11.1.2.x is not enough. You need to install the Android SDK, configure the emulator, configure your device and adjust your JDeveloper preferences. Using release mode will speed up your deployments as well. Solution: Click here to watch Frédéric Desbiens walk you through a solution.