How to add nodes dynamically to a RichTree in Oracle ADF?
Asked Answered
G

2

6

i've been looking for every corner of internet this question, and i didn't have success to find a solution, i made some examples with RichPanelAccordion but i haven't find some equivalent

This is my code for RichPanelAccordion

I create the Header of panel

List<UIComponent> child = getPh3().getChildren();
RichPanelAccordion GCHeader = new RichPanelAccordion();
GCHeader.setId("PanelMenuHeader");
GCHeader.setStyleClass("HeaderGCMenu");
GCHeader.setShortDesc("Menu");
GCHeader.setChildCreation("immediate");

Then add nodes or childs to the Header

RichShowDetailItem PBR = new RichShowDetailItem();
PBR.setText("Child Node");
PBR.setIcon("/Images/config_icon.png");
PBR.setStyleClass("ChildGCMenu");
GCHeader.getChildren().add(PBR);

How can i do this with RichTree instead?

RichTree rt = new RichTree();

Im using JDeveloper

Gauge answered 30/1, 2019 at 18:49 Comment(0)
U
0

For RichTree UIComponent you can add a column as a child.

  RichTree rt = new RichTree();

  RichColumn column1= new RichColumn();
  column1.setDisplayIndex(0);
  column1.setFilterable(false);      
  column1.setHeaderText("Column Header");
  column1.setSortable(true);

  RichOutputText op1 = new RichOutputText();
  op1.setValue("value123");

  column.getChildren().add(op1); 
  rt.getChildren().add(column1);

There are many more attributes, components that you can add to your column component. Hope this answer can act as a pointer.

https://docs.oracle.com/cd/E68505_01/adf/api-reference-faces/oracle/adf/view/rich/component/rich/data/RichTree.html

https://docs.oracle.com/middleware/12211/adf/api-reference-faces/oracle/adf/view/rich/component/rich/data/RichColumn.html

Unbelieving answered 4/2, 2019 at 18:49 Comment(3)
Thanks for your answer, but unfortunately is not working, still appear "No data to display", i added it just like your exampleGauge
Is the "No data to display" appearing instead of the value123 of the children node ? Or for the whole table ?Preteritive
The whole tree.Gauge
C
0

To programmatically add data to ADF tree widget, you will fist have to prepare your own instance of

org.apache.myfaces.trinidad.model.ChildPropertyTreeModel

Here's the constructor documentation

  /**
   * Creates a TreeModel
   * @param instance The Collection of root nodes of this tree.
   * This can be a List or array of beans (or Maps).
   * This instance is first converted into a CollectionModel (see
   * {@link ModelUtils#toCollectionModel}).
   * @param childProperty This property will be used to get at the child Lists
   * from each bean (or Map). Bean rules will be used to find a getter method
   * that matches this property. If each node is a Map, this property will be
   * passed in to the Map's get method to get the child List. 
   */
  public ChildPropertyTreeModel(Object instance, String childProperty)

Once you have populated your TreeModel, you just have to setValue this on the RichTree instance.

The documentation for ChildPropertyTreeModel has some useful tips on how to construct a tree model using simple POJO's

Colorific answered 6/2, 2019 at 11:16 Comment(2)
Thanks for your answer, i've tried do that, but always throw me error NullPointerException when tried to load the tree, you have an example about that code?Gauge
It would be easier to answer if you paste the stack traceColorific

© 2022 - 2024 — McMap. All rights reserved.