ADF Code Corner How-to access the selected row data in an ADF bound ADF Faces TreeTable or Tree. Abstract: twitter.

Similar documents
ADF Code Corner How-to pass values from a parent page to a popup dialog. Abstract: twitter.com/adfcodecorner

ADF Code Corner. 66. How-to color-highlight the bar in a graph that represents the current row in the collection. Abstract: twitter.

ADF Code Corner Drag-and-drop reordering of table rows. Abstract: twitter.com/adfcodecorner

ADF Code Corner. 92. Caching ADF Web Service results for in-memory filtering. Abstract: twitter.com/adfcodecorner

ADF Code Corner How-to drag-and-drop data from an af:table to af:tree. Abstract: twitter.com/adfcodecorner

ADF Code Corner. 81. How-to create master-detail behavior using af:paneltabbed and DVT graph components. Abstract: twitter.

Building an Agile PLM Web Application with JDeveloper and Agile 93 Web Services

Building and Using Web Services With JDeveloper 11g

ADF Code Corner. 86. Reading boilerplate images and icons from a JAR. Abstract: twitter.com/adfcodecorner

Developing Rich Web Applications with Oracle ADF and Oracle WebCenter Portal

The Oracle Fusion Development Platform

Securing Fusion Web Applications

Oracle Application Development Framework Overview

<Insert Picture Here> Betting Big on JavaServer Faces: Components, Tools, and Tricks

ADF Code Corner Building a search form that displays the results in a task flow. Abstract: twitter.com/adfcodecorner

Safe Harbor Statement

<Insert Picture Here> Web 2.0 Data Visualization with JSF. Juan Camilo Ruiz Senior Product Manager Oracle Development Tools

Developing Web and Mobile Dashboards with Oracle ADF

Oracle JDeveloper 10g for Forms & PL/SQL

Oracle Technology Network Virtual Developer Day. Developing RIA Web Applications with Oracle ADF

How To Develop A Mobile Application On An Android Device

An introduction to creating JSF applications in Rational Application Developer Version 8.0

Tutorial on Building a web Application with Jdeveloper using EJB, JPA and Java Server Faces By Phaninder Surapaneni

ADF Code Corner. 77. Handling the af:dialog Ok and CANCEL buttons. Abstract: twitter.com/adfcodecorner

1 Copyright 2011, Oracle and/or its affiliates. All rights reserved.

ADF Code Corner ADF Faces RC - How-to use the Client and Server Listener Component. Abstract: twitter.com/adfcodecorner

ADF Code Corner. Oracle JDeveloper OTN Harvest 08 / Abstract: twitter.com/adfcodecorner

ORACLE ADF MOBILE DATA SHEET

Tutorial: Building a Web Application with Struts

This presentation is for informational purposes only and may not be incorporated into a contract or agreement.

Task Flow Design Fundamentals

<Insert Picture Here> Building a Complex Web Application Using ADF and Siebel

Oracle Business Intelligence ADF Custom Visualizations and Integration. An Oracle White Paper November 2012

Glassfish, JAVA EE, Servlets, JSP, EJB

How To Create A Graph On An African Performance Monitor (Dvt)

User Application: Design Guide

OTN Developer Day: Oracle Big Data. Hands On Lab Manual. Introduction to Oracle NoSQL Database

NetBeans and GlassFish v 2.1 Creating a Healthcare Facility Visual Web Application

Business Scenario Using GP/Web Dynpro with Back and Forth 3 Level Process and Dynamic Approvers in a Loop

ORACLE MOBILE APPLICATION FRAMEWORK DATA SHEET

Oracle Hyperion Financial Management Developer and Customization Guide

Building Web Services with Apache Axis2

Terms and Definitions for CMS Administrators, Architects, and Developers

An Oracle White Paper June Creating an Oracle BI Presentation Layer from Imported Oracle OLAP Cubes


DEVELOPING CONTRACT - DRIVEN WEB SERVICES USING JDEVELOPER. The purpose of this tutorial is to develop a java web service using a top-down approach.

Tutorial Build a simple IBM Rational Publishing Engine (RPE) template for IBM Rational DOORS

The end. Carl Nettelblad

How to Create User-Defined Fields and Tables

Umbrello UML Modeller Handbook

When a business user interacts with an integrated workbook, there are various elements involved in the picture. Each of these elements has its own

Oracle Business Intelligence Server Administration Guide. Version December 2006

ADF. Joe Huang Joe Huang Senior Principal Product Manager, Mobile Development Platform, Oracle Application Development Tools

Design. in NetBeans 6.0

IBM Tivoli Software. Document Version 8. Maximo Asset Management Version 7.5 Releases. QBR (Ad Hoc) Reporting and Report Object Structures

TIBCO ActiveMatrix BPM Mediation Component Development

Practice Fusion API Client Installation Guide for Windows

OBIEE 11g : Answers, Dashboards & More

JIDE Gantt Chart Developer Guide

To Begin Customize Office

Struts Tools Tutorial. Version: M5

Enterprise Service Bus

Oracle Hyperion Financial Management Custom Pages Development Guide

<Insert Picture Here> Michael Hichwa VP Database Development Tools Stuttgart September 18, 2007 Hamburg September 20, 2007

Teradata SQL Assistant Version 13.0 (.Net) Enhancements and Differences. Mike Dempsey

USING MYWEBSQL FIGURE 1: FIRST AUTHENTICATION LAYER (ENTER YOUR REGULAR SIMMONS USERNAME AND PASSWORD)

Selenium Automation set up with TestNG and Eclipse- A Beginners Guide

Developing NFC Applications on the Android Platform. The Definitive Resource

Siebel Web UI Dynamic Developer Kit Guide. Siebel Innovation Pack 2013 Version 8.1/8.2 September 2013

Workshop for WebLogic introduces new tools in support of Java EE 5.0 standards. The support for Java EE5 includes the following technologies:

Oracle Service Bus Examples and Tutorials

Oracle SOA Suite 11g Oracle SOA Suite 11g HL7 Inbound Example

An Oracle White Paper September Oracle Team Productivity Center

Oracle Fusion Middleware

Publishing, Consuming, Deploying and Testing Web Services

HANDS-ON PRACTICE: DEPLOY AN APPLICATION

1 What Are Web Services?

1 What Are Web Services?

JBoss SOAP Web Services User Guide. Version: M5

Database Forms and Reports Tutorial

Understanding Business Process Management

<Insert Picture Here> Oracle Mobile Enterprise Application Platform Overview

Developing WCM based WebSphere Portal application using IBM Rational Application Developer

ORACLE BUSINESS INTELLIGENCE WORKSHOP

Java SE 8 Programming

Have you ever done something the long way and then

Getting Started: Creating a Simple App

Oracle Fusion Middleware

Oracle WebLogic Server

Liferay Enterprise ecommerce. Adding ecommerce functionality to Liferay Reading Time: 10 minutes

Course Number: IAC-SOFT-WDAD Web Design and Application Development

Bitrix Site Manager 4.1. User Guide

<Insert Picture Here> Oracle Application Express 4.0

TIBCO MDM Studio Repository Designer User s Guide

OpenLDAP Oracle Enterprise Gateway Integration Guide

Understanding BEx Query Designer: Part-2 Structures, Selections and Formulas

From Forms to ADF When, Why and How? Senior Group Product Manager - Application Development Tools

Specialized Programme on Web Application Development using Open Source Tools

Don t get it right, just get it written.

Integrating SalesForce with SharePoint 2007 via the Business Data Catalog

Transcription:

ADF Code Corner 026. How-to access the selected row data in an ADF bound Abstract: The ADF Faces af:treetable component displays hierarchical data in a combined tree and table structure. In this, the leading column is displayed as a tree, while subsequent columns, which could represent different hierarchy levels, are displayed in a table format. If you use ADF to bind the af:treetable to business data, then a tree binding definition in the PageDef file is used by the ADF binding layer to provides the CollectionModel instance that is required by the af:treetable as a component model. The question answered in this blog is how developers use Java in a managed bean to determine the hierarchical data that represents the af:treetable row that a user selected. TreeTables and trees share the same bindings, which is why the code examples shown in this article can be used with both, ADF Faces tree and treetable components. twitter.com/adfcodecorner Author: Frank Nimphius, Oracle Corporation twitter.com/fnimphiu 09-NOV-2009

Oracle ADF Code Corner is a loose blog-style series of how-to documents that provide solutions to real world coding problems. Disclaimer: All samples are provided as is with no guarantee for future upgrades or error correction. No support can be given through Oracle customer support. Please post questions or report problems related to the samples in this series on the OTN forum for Oracle JDeveloper: http://forums.oracle.com/forums/forum.jspa?forumid=83 Introduction In ADF, ADF Faces table, tree and tree table components are bound to the tree binding in the ADF binding layer. At runtime, the binding definition file, build as the page's PageDef file, becomes the content of the binding container. The binding container does not operate on XML metadata, but Java objects, which are instances of the FacesCtrl* bindings if using ADF Faces as the user interface. All FacesCtrl* classes extend the generic binding classes, which for the tree binding are JUCtrlHierBinding and JUCtrlHierNodeBinding. So for developers to know what the selected data node is when the user selects a row in a tree table, these two classes are important to know about at least to know they exist. In the following we provide you example code that gives you access to the selected treetable data. 2

Note: The screenshot above is taken using Oracle JDeveloper 11g R1 Patch Set 1, which by the time of writing is not yet publicly available. However, the code examples contained in this article work with any release of Oracle JDeveloper 11g. There is a minor difference between working with ADF Business Components and working with POJOs as the business service, which is why we keep the use cases separated. In both cases, you start by creating the treetable by dragging a Collection from the DataControls palette to the JSF page to then create the tree table. Note that by default, the tree table is created with a single column that is populated by the nodepath facet. To make a tree table out of the initial design, you need to create af:column instances within the af:treetable and add components that render the cell value into them, as shown in the image below The tree table above contains one column definition in the nodestamp facet, which is the name of the city we are looking at. The other four columns represent the departments and associated employees. The visual display at runtime is shown in the image on top. 3

When you configure the cell render component of the af:column component with a data reference, note that you reference a treetable variable and not the "bindings" object. by default the tree table variable is defined as "node". The variable name, which you can change in the Property Inspector, also shows in the Oracle JDeveloper 11g Expression Builder under the JSP Objects node. This provides you with an error free configuration of the EL required to display tree table data. The attributes that are displayed beneath the "node" entry in the Expression Builder represent all the attributes that you selected for access in the tree binding dialog (Since this is an advanced topic we cover here, our assumption is that you know how to create tree rules that build the tree structure in the ADF tree binding dialog) 4

Once you built the treetable, select the component's "binding" property in the PropertyInspector and create a managed bean reference for it. This allows your managed bean to access the instance of the af:treetable component at runtime. Note that another way to access the treetable component at runtime is to search for it in JavaServer Faces UIViewRoot. This latter option allows you to write more generic code and does not require to create a page dependency to a managed bean. If the client logic you execute on the selected treetable row value is initiated by an event raised by the treetable, then the handle to the treetable component instance can be obtained from the event object by calling getsource() on it. ADF Business Components use case The source code below assumes that the user pressed a command button to perform action on the selected af:treetable node. However, as you see, the actionevent object of the command button action listener implementation is not used, which means that the same code can be used elsewhere. import java.util.iterator; import java.util.list; import javax.faces.event.actionevent; import oracle.adf.view.rich.component.rich.data.richtreetable; import oracle.adfdt.model.objects.treetable; import oracle.jbo.uicli.binding.juctrlhierbinding; import oracle.jbo.uicli.binding.juctrlhiernodebinding; import org.apache.myfaces.trinidad.model.collectionmodel; import org.apache.myfaces.trinidad.model.rowkeyset; public class TreeTableHandlerBean { private RichTreeTable treetable1; public TreeTableHandlerBean() { //user action handling public void onrowcreateaction(actionevent actionevent) { RichTreeTable treetable = this.gettreetable1(); //get selected row keys. This could be a single entry or //multiple entries dependent on whether the tree table is //configured for multi row selection or single row selection RowKeySet rks = treetable.getselectedrowkeys(); Iterator rksiterator = rks.iterator(); //assuming single select use case. Otherwise, this is where you //need to add iteration over the entries in the multi select use case if (rksiterator.hasnext()){ //a key is a list object that containe the node path information //for the selected node List key = (List)rksIterator.next(); //determine the selected node. Note that the tree table binding is //an instance of JUCtrlHierBinding JUCtrlHierBinding treetablebinding = null; //We can get the binding information without using EL in our Java, //which you always should try to do. Using EL in Java is good to //use, but only second best as a solution treetablebinding = (JUCtrlHierBinding) ((CollectionModel)treeTable.getValue()).getWrappedData(); 5

//the row data is represented by the JUCtrlHierNodeBinding class at //runtime. We get the node value from the tree binding at runtime JUCtrlHierNodeBinding nodebinding = treetablebinding.findnodebykeypath(key); //the JUCtrlHierNodeBinding object allows you to access the row data, //so if all you want is to get the selected row data, then you are //done already. However, in many cases you need to further //distinguish the node, which is what we can do using the //HierTypeBinding String nodestucturedefname = nodebinding.gethiertypebinding().getstructuredefname(); //determine the selected node by the ViewObject name and package String departmentsdef = "adf.sample.model.departmentsview"; String employeesdef = "adf.sample.model.employeesview"; String locationsdef = "adf.sample.model.locationsview"; if (nodestucturedefname.equalsignorecase(locationsdef)){ //work with location node data else if (nodestucturedefname.equalsignorecase(departmentsdef)){ //work with departments node data else if (nodestucturedefname.equalsignorecase(employeesdef)){ //work with location node data else{ //what the heck did the user click on? Ask him ;-)... access to the treetable instance... Note: If the child node is a read only View Object, make sure the View Object has a primary key defined. If the View Object queries multiple tables then the key need to be set for more than one attribute. Open the VO, select an attribute and check the "key" checkbox. If you don't do this, a NPE is thrown Pojo use case The code you use for the POJO use case is slightly different in the way the row data is accessed. Also, since we are working with POJOs, we determine the node level by checking the node object instance against the POJO objects. The sample code below actually determines the selected node / row value in an ADF Faces tree. The source code though is the same as when working with an af:treetable component since the underying ADF bindingstructure is identical. This also is a great example of how learning a single API allows to you program against different business services and UI components. import java.util.list; import javax.faces.event.actionevent; import oracle.adf.model.bean.dcdatarow; 6

import oracle.adf.view.rich.component.rich.data.richtree import oracle.jbo.uicli.binding.juctrlhierbinding; import oracle.jbo.uicli.binding.juctrlhiernodebinding; //my custom POJO entities import oracle.pojo.entities.departments; import oracle.pojo.entities.employees; import oracle.pojo.entities.locations; //trinidad classes import org.apache.myfaces.trinidad.model.collectionmodel; import org.apache.myfaces.trinidad.model.rowkeyset; public class TreeBean { //this example uses a tree. However, the data access is the same as //for tree tables using an ADF tree binding private RichTree locationtree; public TreeBean() { //method executed when the user presses the command button in our //example public void onrowcreateaction(actionevent actionevent) { //get access to the Tree Collection Model. The tree component //instance is accessed through its binding property reference //to this managed bean CollectionModel treemodel = null; //access the tree component from a JSF component binding, a search on //the UIViewRoot, or if the method is invoked from a tree event, from //the getsource() call treemodel = (CollectionModel) this.gettree().getvalue(); //The CollectionModel is of type FacesModel, which is an inner class. //To get to the ADF tree binding, we can call wrappeddata on the //Collection Model JUCtrlHierBinding treebinding = (JUCtrlHierBinding) treemodel.getwrappeddata(); //get the selected tree nodes RowKeySet rks = locationtree.getselectedrowkeys(); //If there is a tree node selected... if(!rks.isempty()){ //get first selected node as we assume this code to execute in a //single row selection use case. Iterate over the whole iterator if //you are in a multi node selection case List firstset = (List)rks.iterator().next(); //get the ADF node binding. If you want to access sub nodes, make //sure that you set the primary key attribute for the entity //representing this node. 7

//If you don't do this, the next line throws an NPE JUCtrlHierNodeBinding node = treebinding.findnodebykeypath(firstset); //The Row is of type DCDataRow, a binding class not often used, //especially if you are used to the Fusion development environment DCDataRow rw = (DCDataRow) node.getrow(); //The data provider is the object - the entity - that is used to //render the node. Object entity = rw.getdataprovider(); //determine the object so you can type cast it if needed. if (entity instanceof Locations){ //do some location work here return; if (entity instanceof Departments){ //do some department work here return; if (entity instanceof Employees){ //do some employee work here return;... access to the tree instance... In this example, note the use of the DCDataRow class to access the entity that represents the selected node/row. Note that the DCDataRow object is another ADF binding class. Also note how similar the code shown above is compared to the ADF Business Components example where we used the af:treetable component. Disclaimer The content of this blog article is an advanced topic and is not representative for working with ADF. If you are a beginner with ADF, don't be too impressed with the content - or shocked because you don't understand it in detail. As a beginner your initial look should be at the developer guides published in the documentation section on OTN and www.oracle.com, as well as the Oracle by Example tutorials. Sooner or later you will come back to this example, fully understanding what it does and enjoying the power that ADF provides beyond drag and drop development. This blog example explains how to access the selected tree node or tree table node data from Java, which a use business use case may require you to do. There also is a strategy to get the same information declaratively using Expression Language. For example, using ADF Business Components, you create iterators for the View Objects that have data representations in the tree structure. The tree binding can be configured to make sure that the selected node always synchronizes the iterator. Creating attribute bindings for the iterators and reference them from ADF Faces input components, allow to easily and 8

declaratively building input forms for the selected tree nodes. After all, ADF is there to simplify Java EE development using declarative development gestures. However, if the use case demands it that you need to access the selected hierarchical structure value in Java, then no you know. RELATED DOCOMENTATION 9