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

Similar documents
ADF Code Corner Drag-and-drop reordering of table rows. 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. 92. Caching ADF Web Service results for in-memory filtering. Abstract: twitter.com/adfcodecorner

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

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

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

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

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

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

Building and Using Web Services With JDeveloper 11g

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

The Oracle Fusion Development Platform

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

Specialized Programme on Web Application Development using Open Source Tools

Foglight. Dashboard Support Guide

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

Task Flow Design Fundamentals

Developing Rich Web Applications with Oracle ADF and Oracle WebCenter Portal

Smooks Dev Tools Reference Guide. Version: GA

Subversion Integration for Visual Studio

Specialized Programme on Web Application Development using Open Source Tools

Tutorial: Building a Web Application with Struts

Getting Started with Telerik Data Access. Contents

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

Importing TSM Data into Microsoft Excel using Microsoft Query

ORACLE ADF MOBILE DATA SHEET

T300 Acumatica Customization Platform

HP Quality Center. Upgrade Preparation Guide

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

Web Intelligence User Guide

Oracle Application Development Framework Overview

Integrating SalesForce with SharePoint 2007 via the Business Data Catalog

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

Configuring the SST DeviceNet OPC Server

Oracle Data Miner (Extension of SQL Developer 4.0)

AIReS. Company: American International Relocation Solutions. Industry: Domestic and Global Relocation Solutions

Getting Started with Android Smartphones and ThingWorx

HPCC Data Handling. Boca Raton Documentation Team

Build a Mobile App in 60 Minutes with MAF

Developing Web and Mobile Dashboards with Oracle ADF

isupplier PORTAL ACCESS SYSTEM REQUIREMENTS

User Application: Design Guide

Mobile Solutions for Data Collection. Sarah Croft and Laura Pierik

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

Store, Edit and Share your files in OneDrive for Business on Web. A. Activate OneDrive for Business (Only for First-time Users)

IBM DB2 XML support. How to Configure the IBM DB2 Support in oxygen

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

AWS Schema Conversion Tool. User Guide Version 1.0

MyOra 3.0. User Guide. SQL Tool for Oracle. Jayam Systems, LLC

HelpSystems Web Server User Guide

CA Identity Manager. Glossary. r12.5 SP8

1.1 Installing Protégé You can follow the steps below to download and install Protégé from the source.

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

Intelligent Event Processer (IEP) Tutorial Detection of Insider Stock Trading

WebSphere Business Monitor

PeopleTools 8.51 PeopleBook: PeopleSoft Application Designer Lifecycle Management Guide

Oracle JDeveloper 10g for Forms & PL/SQL

ultimo theme Update Guide Copyright Infortis All rights reserved

LDAP Server Configuration Example

Talend Open Studio for MDM. Getting Started Guide 6.0.0

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

Working with SQL Server Integration Services

An Oracle White Paper September Oracle Team Productivity Center

From Data Modeling to Data Dictionary Written Date : January 20, 2014

Oracle Hyperion Financial Management Custom Pages Development Guide

Application. 1.1 About This Tutorial Tutorial Requirements Provided Files

Activities Manual. Product Manual. Table of Contents. 1. efolio Overview Benefits

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

Business Process Management IBM Business Process Manager V7.5

Developing SQL and PL/SQL with JDeveloper

ORACLE MOBILE APPLICATION FRAMEWORK DATA SHEET

<Insert Picture Here>

QAS Small Business for Salesforce CRM

Central Security Server

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

Crystal Reports for Eclipse

ultimo theme Update Guide Copyright Infortis All rights reserved

Viewing and Adding Photos

Portal Factory CMIS Connector Module documentation

Mitigation Planning Portal MPP Reporting System

MA-WA1920: Enterprise iphone and ipad Programming

Siebel Application Services Interface Reference. Siebel Innovation Pack 2013 Version 8.1/8.2 September 2013

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

Sage 300 ERP Sage CRM 7.2 Integration Guide

TIBCO Spotfire Automation Services Installation and Configuration

Recruiting Hiring Managers. Guide for Users Updated on 28 June 2016

Witango Application Server 6. Installation Guide for Windows

Advantech WebAccess Device Driver Guide. BwSNMP Advantech WebAccess to SNMP Agent (Simple Network Management Protocol) Device Driver Guide

Oracle Forms 10g Dynamic LOVs

BUSINESS RULES CONCEPTS... 2 BUSINESS RULE ENGINE ARCHITECTURE By using the RETE Algorithm Benefits of RETE Algorithm...

Rational Team Concert. Quick Start Tutorial

Transcription:

ADF Code Corner 101. How-to drag-and-drop data from an af:table to af:tree Abstract: Drag and drop is a feature of the ADF Faces framework. All developers have to do to make this work is to add a drag source tag to the component that is the origin of a drag operation and a drop tag to the component that is the desitination of this operation. This article provides a sample and explanation of how to develop drag and drop between an AD bound ADF Faces table and an ADF Faces tree component. twitter.com/adfcodecorner Author: Frank Nimphius, Oracle Corporation twitter.com/fnimphiu 13-JUN-2012

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 The Oracle JDeveloper 11g R1 (11.1.1.6) sample application you can download from a link at the end of this article shows a table of employees to the left and a tree component to the right. You can drag one or multiple rows from the table and drop it onto the tree component. If the drop is to a node that is not a department, an information alert is shown 2

If the drop is on a department node then the employee accounts within the drop are updated with the department ID of the drop target. The tree is refreshed and the department node with the new employee nodes expanded. Note that the sample does not commit the data changes to preserve the state of your HR schema data. The sample code has a couple of useful code examples, like Handling a drop event for a data collection Determine the node type of the drop Avoiding conflicts due to programmatic changes of the tree row state 3

Expanding specific tree node path Implementing drag and drop The implementation of drag and drop between an ADF Faces table and a tree is not complicated at all, as you can tell from the page source shown below: <af:table value="#{bindings.employeesview1.collectionmodel" var="row" rows="#{bindings.employeesview1.rangesize"..."> <af:dragsource actions="move" discriminant="rowmove" defaultaction="move"/> <af:column...>... </af:column> The af:dragsource tag is an immediate child of the af:table component. The discriminant property allows you to associate a specific drag event with this drop target so that users cannot make mistakes in pages that support drag and drop on multiple components. The action MOVE provides an additional discriminator in that the drag only occurs on drop targets that also support the MOVE action. Other action types are COPY and LINK. The drop component in this sample is the ADF Faces tree component. The configuration is shown below <af:tree value="#{bindings.locationsview11.treemodel" var="node" selectionlistener="#{bindings.locationsview11.treemodel.makecurrent" rowselection="single" id="t2"> <f:facet name="nodestamp"> <af:outputtext value="#{node" id="ot11"/> </f:facet> <af:collectiondroptarget droplistener="#{drophandlerbean.drophandler" actions="move" modelname="rowmove"/> </af:tree> As mentioned, the implementation of drag and drop in ADF Faces is not difficult. The drop target is defined by the af:collectiondroptarget droplistener, which is an immediate child of the af:tree component. The modelname property matches the discriminant property value of the drag source. If the action wasn't MOVE but COPY or LINK then no drop would be allowed. Note that you can define multiple actions, for example actions="copy MOVE" The drop handler code If the implementation of drag and drop on the page is so simple, then there must be power within the managed bean method that handles the drop event. The beauty of drag and drop in ADF Faces is that it 4

takes the burden of cross-browser drag-and-drop JavaScript development from the application developer and instead delegates the event handling to Java in a managed bean. import java.util.arraylist; import java.util.iterator; import java.util.list; import java.util.map; import javax.faces.component.contextcallback; import javax.faces.component.uicomponent; import javax.faces.component.uiviewroot; import javax.faces.context.facescontext; import oracle.adf.model.bean.dcdatarow; import oracle.adf.view.rich.component.rich.richpopup; import oracle.adf.view.rich.component.rich.data.richtable; import oracle.adf.view.rich.component.rich.data.richtree; import oracle.adf.view.rich.context.adffacescontext; import oracle.adf.view.rich.datatransfer.dataflavor; import oracle.adf.view.rich.datatransfer.transferable; import oracle.adf.view.rich.dnd.dndaction; import oracle.adf.view.rich.event.dropevent; import oracle.jbo.row; import oracle.jbo.uicli.binding.juctrlhierbinding; import oracle.jbo.uicli.binding.juctrlhiernodebinding; import org.apache.myfaces.trinidad.event.pollevent; import org.apache.myfaces.trinidad.event.selectionevent; import org.apache.myfaces.trinidad.model.collectionmodel; import org.apache.myfaces.trinidad.model.rowkeyset; import org.apache.myfaces.trinidad.model.rowkeysetimpl; public class DropHandlerBean { //Variable holding the component looked up on a page. See //"findcomponentonpage" method in this class that allows //you to get a handle to any component in a view by the //component ID using an optimized search explained in ADF //Code Corner sample #58 //http://www.oracle.com/technetwork/developer-tools/adf/downloads/58- //optimizedadffacescomponentsearch-175858.pdf private UIComponent lookupcomponent = null; public DropHandlerBean() { public DnDAction drophandler(dropevent dropevent) { //get handle to drag component 5

RichTable table = (RichTable) dropevent.getdragcomponent(); //get handle to drop component RichTree tree = (RichTree) dropevent.getdropcomponent(); //memorize current row key to restore the original selection state //of the tree to avoid issues with context menus or similar. Note //that this step is important and should never be omitted when you //programmatically change the row key for trees, tables and tree //tables Object currentrowkey = tree.getrowkey(); //the drop site tells us about the node that received the drop //event. In this use case we only allow the department node to //handle the drop. For others we show a user information in a //popup List droprowkey = (List) dropevent.getdropsite(); //if no dropsite then drop area was not a data area if(droprowkey == null){ return DnDAction.NONE; //make row current so we can access it. This line of code is //the reason why we needed to keep track of the original tree //selection state. Here we programmatically change the row //currency without telling the underlying ADF binding layer. //If we don't set the row selection back to the original value //we would risk the binding layer (model) and the client tree //state to go out of synch tree.setrowkey(droprowkey); JUCtrlHierNodeBinding dropnode = (JUCtrlHierNodeBinding) tree.getrowdata(); String dropnodevo = dropnode.gethiertypebinding().getstructuredefname(); //The ADF Binding layer tells us about the structure definition //name of a node. If you select a node in the binding editor then //a string like shown below is displayed for each node. Using this //information you can tell what type the node is of. In our case //if the type is department, the drop is allowed if (dropnodevo.equalsignorecase ("adf.sample.model.vo.departmentsview")) { Row treerow = dropnode.getrow(); Transferable t = dropevent.gettransferable(); DataFlavor<RowKeySet> df = DataFlavor.getDataFlavor(RowKeySet.class, "rowmove"); RowKeySet rks = t.getdata(df); Iterator iter = rks.iterator(); 6

//we allow multi-row drag and drop so that multiple employees //can be relocated at the same time while (iter.hasnext()) { //get next selected row key List key = (List)iter.next(); table.setrowkey(key); //the table model represents its row by the ADF binding class, //which is JUCtrlHierNodeBinding JUCtrlHierNodeBinding rowbinding = (JUCtrlHierNodeBinding)table.getRowData(); //DCDataRow is the generic row class representation in in ADF. //It is the super class of oracle.jbo.row, which you use with //ADF BC services Row tablerow = (Row)rowBinding.getRow(); //to relocate employees, just change the department ID tablerow.setattribute("departmentid", treerow.getattribute("departmentid")); //set current row key back tree.setrowkey(currentrowkey); //Show the employees in their new department by expanding the //target department node. For this we need to // 1. get access to the ADF tree binding // 2. iteratively get all parent nodes // 3. get the child nodes (employees) of the drop node //1. get access to the ADF tree binding. We get this from the //tree instance we obtained from the dropevent target CollectionModel treemodel = (CollectionModel) tree.getvalue(); JUCtrlHierBinding treebinding = (JUCtrlHierBinding) treemodel.getwrappeddata(); //create a new row key set RowKeySetImpl rksimpl = new RowKeySetImpl(); rksimpl.add(droprowkey); //2. Get all parent nodes node path information to add to the //row key set to disclose the node 7

JUCtrlHierNodeBinding treedropnode = treebinding.findnodebykeypath(droprowkey); JUCtrlHierNodeBinding rootnode = treebinding.getrootnodebinding(); JUCtrlHierNodeBinding dropnodeparent = treedropnode.getparent(); //walk up the tree to expand all parent nodes while(dropnodeparent!= null && dropnodeparent!= rootnode){ rksimpl.add(dropnodeparent.getkeypath()); dropnodeparent = dropnodeparent.getparent(); //3. get all employee nodes in a tree to disclose them too ArrayList<JUCtrlHierNodeBinding> childlist = (ArrayList<JUCtrlHierNodeBinding>) treedropnode.getchildren(); for(juctrlhiernodebinding nb : childlist){ rksimpl.add(nb.getkeypath()); //ready to disclose tree.setdisclosedrowkeys(rksimpl); AdfFacesContext.getCurrentInstance().addPartialTarget(tree.getParent()); AdfFacesContext.getCurrentInstance().addPartialTarget(table); return DnDAction.MOVE; //set current row key back tree.setrowkey(currentrowkey); //notify the user about failed drop RichPopup userinfo = (RichPopup) findcomponentonpage("p2"); RichPopup.PopupHints hints = new RichPopup.PopupHints(); userinfo.show(hints); return DnDAction.NONE; private UIComponent findcomponentonpage(string id){ String comp = id; //see ADF Code Corner sample #58 to read about the code //used in the search below FacesContext fctx = FacesContext.getCurrentInstance(); UIViewRoot root = fctx.getviewroot(); root.invokeoncomponent(fctx,comp, new ContextCallback(){ public void invokecontextcallback(facescontext facescontext, 8

UIComponent uicomponent) { lookupcomponent = uicomponent; ); return lookupcomponent; Download You can download the Oracle JDeveloper 11.1.1.6 sample application from ADF Code Corner where it is sample # 101 http://www.oracle.com/technetwork/developer-tools/adf/learnmore/index-101235.html You need to configure the database connection to point to the HR schema in your local database. RELATED DOCOMENTATION 9