Displaying Hierarchical Data from a Web Service in JSF with ADF

Someone asked on OTN if we can use data coming from a Web service to populate a hierarchical tree in a JSF page.
The answer is yes - and with the Web service data control this is actually very simple in JDeveloper 11g.

Here is a quick demo:

Comments:

Hi Shay,

Is there a way by which I can display a check box in front of every node in af:tree. And whenever I select a node, all the children should be selected.
If yes, how to do it, and how to read the selected values?

Thanks in advance.

Posted by Sachin Gupta on November 29, 2011 at 04:34 AM PST #

Sachin, you should be able to add a checkbox in the tree node - but you'll need to programatically code the selection of the node and all the children in that checkbox's listener.

Posted by Shay on November 29, 2011 at 06:34 AM PST #

Hey Shay, The video is not available. Can u upload it again.Thanks, Ravi.

Posted by guest on January 22, 2012 at 10:12 AM PST #

guest - the video works fine for me - make sure you can watch youtube videos on your machine - also available from my youtube channel at:
http://www.youtube.com/watch?v=ImDwxof7_xY

Posted by Shay on January 23, 2012 at 09:30 AM PST #

Please let me know where do I get the source code(Web services code)of this video.

Posted by Sumit Dey on May 21, 2012 at 12:08 PM PDT #

Sumit, the basic workspace I use for the Webservice is here:
https://blogs.oracle.com/shay/resource/pojo.zip

Posted by Shay on May 21, 2012 at 04:28 PM PDT #

Is it possible to reverse the tree hierarchy (Last node becomes the first node), if possible how we can implement that.

Posted by Sumit Dey on May 23, 2012 at 12:19 PM PDT #

Sumit - it all depends on the model that populate the tree - so if your model is reversed the tree would show it accordingly. There is no built in function to do this automatically.

Posted by Shay on May 23, 2012 at 04:48 PM PDT #

I want to show details of tree control data dynamically, suppose I have created a tree with 5 levels, First use a panelSpliter for the application. Left hand side I have added a tree control other side of spliter would be show details form, now I able able to show details on 2nd part of panelSpliter, but I want to show details in different hierarchy level in same area, now I can able to show the details to the different tab, but now I want to show that when I click on a node, it should show in same place (don't want to show in different tabs or different place).[every level have their own view (Data Control)]

Thanks in advance.

Posted by Sumit Dey on May 24, 2012 at 04:22 PM PDT #

Sumit - so your question is can I show different things on one side of the page based on what was clicked in a tree?
The answer is yes - you can use dynamic regions to get this.
For example:
http://biemond.blogspot.com/2008/10/dynamic-regions-with-task-flow-in.html

Posted by Shay on May 24, 2012 at 04:38 PM PDT #

Hi Shay,
I am trying to get selected values of a tree, but at a time I am getting only single selection. Can u suggest what changes I need to make below inorder to get selected values.

public void treeTableSelectionListener(SelectionEvent selectionEvent) {
String adfSelectionListener = "#{bindings.Return.treeModel.makeCurrent}";

FacesContext fctx = FacesContext.getCurrentInstance();
Application application = fctx.getApplication();
ELContext elCtx = fctx.getELContext();
ExpressionFactory exprFactory = application.getExpressionFactory();
MethodExpression me = null;
me =
exprFactory.createMethodExpression(elCtx, adfSelectionListener, Object.class, new Class[] { SelectionEvent.class });
me.invoke(elCtx, new Object[] { selectionEvent });

RichTreeTable tree = (RichTreeTable)selectionEvent.getSource();
TreeModel model = (TreeModel)tree.getValue();
//get selected nodes
RowKeySet rowKeySet = selectionEvent.getAddedSet();
Iterator rksIterator = rowKeySet.iterator();
while (rksIterator.hasNext()) {
List key = (List)rksIterator.next();
JUCtrlHierBinding treeBinding = null;
treeBinding = (JUCtrlHierBinding)((CollectionModel)tree.getValue()).getWrappedData();
JUCtrlHierNodeBinding nodeBinding = treeBinding.findNodeByKeyPath(key);
Row rw = nodeBinding.getRow();
System.out.println("row: " + rw.getAttribute(0)); // You can get any attribute
actualList = new ArrayList<SelectItem>();

actualList.add(new SelectItem(rw.getAttribute(0)));
System.out.println("View Object name---->" + nodeBinding.getViewObject().getName());
setActualList(actualList);

}
// AdfFacesContext.getCurrentInstance().addPartialTarget(rwe);

}

Posted by Abhijit on July 20, 2013 at 10:22 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

me
I'm a Director of Product Management for the Oracle Java Development Tools.
Follow me:
Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today