X

The blog for hints & tips about Oracle Application Development Framework and Mobile Application Framework

  • ADFv
    June 11, 2012

Solving the context menu problem with drag and drop in trees

Frank Nimphius
Master Principal Product Manager

The following drag-and-drop problem has been reported on
OTN: An ADF Faces tree component is configured with a af:collectionDropTarget
tag to handle drop events. The same tree component also has a context menu defined
that is shown when users select the tree with the right mouse button. The
problem now was - and I could reproduce this - that the context menu stopped
working after the first time the tree handled a drop event. The drag and drop
use case is to associate employees from a table to a department in the tree
using drag and drop.

The drop handler code in the managed bean looked up the
tree node that received the drop event to determine the department ID to assign
to the employee. For this code similar to the one shown below was used

List dropRowKey = (List) dropEvent.getDropSite();
//if no dropsite then drop area was not a data area
if(dropRowKey == null){
   return DnDAction.NONE;
}               
tree.setRowKey(dropRowKey);
JUCtrlHierNodeBinding dropNode = (JUCtrlHierNodeBinding) tree.getRowData();

So what happens in this code? The drop event contains the dropSite reference, which is the row key
of the tree node that received the drop event. The code then sets the key to
the tree in a call to getRowDate() returns the node information for the drop
target (the department). This however causes the tree state to go out of synch
with its model (ADF tree binding), which is known to cause issues.

In this use case the issue caused by this is that the context menu no
longer shows up. To fix the problem, the code needs to be changes to read the
current row key from the key, then perform the drop operation and at the end
set the origin (or model) row key back

//memorize current row key
Object currentRowKey = tree.getRowKey();       
List dropRowKey = (List) dropEvent.getDropSite();
//if no dropsite then drop area was not a data area
if(dropRowKey == null){
  return DnDAction.NONE;
  }             
tree.setRowKey(dropRowKey);
JUCtrlHierNodeBinding dropNode = (JUCtrlHierNodeBinding) tree.getRowData();
... do your stuff here ....
//set current row key back
tree.setRowKey(currentRowKey);
AdfFacesContext.getCurrentInstance().addPartialTarget(tree);

Note the code line that sets the row key back to its original value.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.