F Code Samples

This appendix provides the full length code samples referenced from sections throughout this guide.

This appendix includes the following sections:

F.1 Samples for Chapter 4, "Using ADF Faces Client-Side Architecture"

Following are code examples for using ADF Faces architecture

F.1.1 The adf-js-partitions.xml File

The default ADF Faces adf-js-partitions.xml file has partitions that you can override by creating your own partitions file. For more information, see Section 4.9, "JavaScript Library Partitioning." Example F-1 shows the default ADF Faces adf-js-partitions.xml file.

Example F-1 The Default adf-js-partitions.xml File

<?xml version="1.0" encoding="utf-8"?>
 
<partitions xmlns="http://xmlns.oracle.com/adf/faces/partition">
 
  <partition>
    <partition-name>boot</partition-name>
    <feature>AdfBootstrap</feature>
  </partition>
 
  <partition>
    <partition-name>core</partition-name>
 
    <feature>AdfCore</feature>
 
    <!-- Behavioral component super classes -->
    <feature>AdfUIChoose</feature>
    <feature>AdfUICollection</feature>
    <feature>AdfUICommand</feature>
    <feature>AdfUIDialog</feature>
    <feature>AdfUIDocument</feature>
    <feature>AdfUIEditableValue</feature>
    <feature>AdfUIForm</feature>
    <feature>AdfUIGo</feature>
    <feature>AdfUIInput</feature>
    <feature>AdfUIObject</feature>
    <feature>AdfUIOutput</feature>
    <feature>AdfUIPanel</feature>
    <feature>AdfUIPopup</feature>
    <feature>AdfUISelectBoolean</feature>
    <feature>AdfUISelectInput</feature>
    <feature>AdfUISelectOne</feature>
    <feature>AdfUISelectMany</feature>
    <feature>AdfUIShowDetail</feature>
    <feature>AdfUISubform</feature>
    <feature>AdfUIValue</feature>
 
    <!-- These are all so common that we group them with core -->
    <feature>AdfRichDocument</feature>
    <feature>AdfRichForm</feature>
    <feature>AdfRichPopup</feature>
    <feature>AdfRichSubform</feature>
    <feature>AdfRichCommandButton</feature>
    <feature>AdfRichCommandLink</feature>
 
    <!-- 
      Dialog is currently on every page for messaging.  No use
      in putting these in a separate partition.
    -->
    <feature>AdfRichPanelWindow</feature>
    <feature>AdfRichDialog</feature>
 
    <!-- af:showPopupBehavior is so small/common, belongs in core -->
    <feature>AdfShowPopupBehavior</feature>
  </partition>
 
  <partition>
    <partition-name>accordion</partition-name>
    <feature>AdfRichPanelAccordion</feature>
  </partition>
 
  <partition>
    <partition-name>border</partition-name>
    <feature>AdfRichPanelBorderLayout</feature>
  </partition>
 
  <partition>
    <partition-name>box</partition-name>
    <feature>AdfRichPanelBox</feature>
  </partition>
  
  <partition>
    <partition-name>calendar</partition-name>
    <feature>AdfUICalendar</feature>
    <feature>AdfRichCalendar</feature>
    <feature>AdfCalendarDragSource</feature>
    <feature>AdfCalendarDropTarget</feature>
  </partition>
  
  <partition>
    <partition-name>collection</partition-name>
    <feature>AdfUIDecorateCollection</feature>
    <feature>AdfRichPanelCollection</feature>
  </partition>
 
  <partition>
    <partition-name>color</partition-name>
    <feature>AdfRichChooseColor</feature>
    <feature>AdfRichInputColor</feature>
  </partition>
 
  <partition>
    <partition-name>date</partition-name>
    <feature>AdfRichChooseDate</feature>
    <feature>AdfRichInputDate</feature>
  </partition>
 
  <partition>
    <partition-name>declarativeComponent</partition-name>
    <feature>AdfUIInclude</feature>
    <feature>AdfUIDeclarativeComponent</feature>
    <feature>AdfRichDeclarativeComponent</feature>
  </partition>
 
  <partition>
    <partition-name>detail</partition-name>
    <feature>AdfRichShowDetail</feature>
  </partition>
 
  <partition>
    <partition-name>dnd</partition-name>
    <feature>AdfDragAndDrop</feature>
    <feature>AdfCollectionDragSource</feature>
    <feature>AdfStampedDropTarget</feature>
    <feature>AdfCollectionDropTarget</feature>
    <feature>AdfAttributeDragSource</feature>
    <feature>AdfAttributeDropTarget</feature>
    <feature>AdfComponentDragSource</feature>
    <feature>AdfDropTarget</feature>    
  </partition>
  
  <partition>
    <partition-name>detailitem</partition-name>
    <feature>AdfRichShowDetailItem</feature>
  </partition>
 
  <partition>
    <partition-name>file</partition-name>
    <feature>AdfRichInputFile</feature>
  </partition>
 
  <partition>
    <partition-name>form</partition-name>
    <feature>AdfRichPanelFormLayout</feature>
    <feature>AdfRichPanelLabelAndMessage</feature>
  </partition>
 
  <partition>
    <partition-name>format</partition-name>
    <feature>AdfRichOutputFormatted</feature>
  </partition>
 
  <partition>
    <partition-name>frame</partition-name>
    <feature>AdfRichInlineFrame</feature>
  </partition>
 
  <partition>
    <partition-name>header</partition-name>
    <feature>AdfRichPanelHeader</feature>
    <feature>AdfRichShowDetailHeader</feature>
  </partition>
 
  <partition>
    <partition-name>imagelink</partition-name>
    <feature>AdfRichCommandImageLink</feature>
  </partition>
 
  <partition>
    <partition-name>iedit</partition-name>
    <feature>AdfInlineEditing</feature>
  </partition>
 
  <partition>
    <partition-name>input</partition-name>
    <feature>AdfRichInputText</feature>
    <feature>AdfInsertTextBehavior</feature>
  </partition>
 
  <partition>
    <partition-name>label</partition-name>
    <feature>AdfRichOutputLabel</feature>
  </partition>
 
  <partition>
    <partition-name>list</partition-name>
    <feature>AdfRichPanelList</feature>
  </partition>
 
  <partition>
    <partition-name>lov</partition-name>
    <feature>AdfUIInputPopup</feature>
    <feature>AdfRichInputComboboxListOfValues</feature>
    <feature>AdfRichInputListOfValues</feature>
  </partition>
 
  <partition>
    <partition-name>media</partition-name>
    <feature>AdfRichMedia</feature>
  </partition>
 
  <partition>
    <partition-name>message</partition-name>
    <feature>AdfUIMessage</feature>
    <feature>AdfUIMessages</feature>
    <feature>AdfRichMessage</feature>
    <feature>AdfRichMessages</feature>
  </partition>
 
  <partition>
    <partition-name>menu</partition-name>
    <feature>AdfRichCommandMenuItem</feature>
    <feature>AdfRichGoMenuItem</feature>
    <feature>AdfRichMenuBar</feature>
    <feature>AdfRichMenu</feature>
  </partition>
 
  <partition>
    <partition-name>nav</partition-name>
    <feature>AdfUINavigationPath</feature>
    <feature>AdfUINavigationLevel</feature>
    <feature>AdfRichBreadCrumbs</feature>
    <feature>AdfRichCommandNavigationItem</feature>
    <feature>AdfRichNavigationPane</feature>
  </partition>
 
  <partition>
    <partition-name>note</partition-name>
    <feature>AdfRichNoteWindow</feature>
  </partition>
 
  <partition>
    <partition-name>poll</partition-name>
    <feature>AdfUIPoll</feature>
    <feature>AdfRichPoll</feature>
  </partition>
 
  <partition>
    <partition-name>progress</partition-name>
    <feature>AdfUIProgress</feature>
    <feature>AdfRichProgressIndicator</feature>
  </partition>
 
  <partition>
    <partition-name>print</partition-name>
    <feature>AdfShowPrintablePageBehavior</feature>
  </partition>
 
  <partition>
    <partition-name>scrollComponentIntoView</partition-name>
    <feature>AdfScrollComponentIntoViewBehavior</feature>
  </partition>
 
  <partition>
    <partition-name>query</partition-name>
    <feature>AdfUIQuery</feature>
    <feature>AdfRichQuery</feature>
    <feature>AdfRichQuickQuery</feature>
  </partition>
 
  <partition>
    <partition-name>region</partition-name>
    <feature>AdfUIRegion</feature>
    <feature>AdfRichRegion</feature>
  </partition>
 
  <partition>
    <partition-name>reset</partition-name>
    <feature>AdfUIReset</feature>
    <feature>AdfRichResetButton</feature>
  </partition>
 
  <partition>
    <partition-name>rte</partition-name>
    <feature>AdfRichTextEditor</feature>
    <feature>AdfRichTextEditorInsertBehavior</feature>
  </partition>
 
  <partition>
    <partition-name>select</partition-name>
 
    <feature>AdfRichSelectBooleanCheckbox</feature>
    <feature>AdfRichSelectBooleanRadio</feature>
    <feature>AdfRichSelectManyCheckbox</feature>
    <feature>AdfRichSelectOneRadio</feature>
  </partition>
 
  <partition>
    <partition-name>selectmanychoice</partition-name>
    <feature>AdfRichSelectManyChoice</feature>
  </partition>
 
  <partition>
    <partition-name>selectmanylistbox</partition-name>
    <feature>AdfRichSelectManyListbox</feature>
  </partition>
 
  <partition>
    <partition-name>selectonechoice</partition-name>
    <feature>AdfRichSelectOneChoice</feature>
  </partition>
 
  <partition>
    <partition-name>selectonelistbox</partition-name>
    <feature>AdfRichSelectOneListbox</feature>
  </partition>
 
  <partition>
    <partition-name>shuttle</partition-name>
    <feature>AdfUISelectOrder</feature>
    <feature>AdfRichSelectManyShuttle</feature>
    <feature>AdfRichSelectOrderShuttle</feature>
  </partition>
 
  <partition>
    <partition-name>slide</partition-name>
    <feature>AdfRichInputNumberSlider</feature>
    <feature>AdfRichInputRangeSlider</feature>
  </partition>
 
  <partition>
    <partition-name>spin</partition-name>
    <feature>AdfRichInputNumberSpinbox</feature>
  </partition>
 
  <partition>
    <partition-name>status</partition-name>
    <feature>AdfRichStatusIndicator</feature>
  </partition>
 
  <partition>
    <partition-name>stretch</partition-name>
    <feature>AdfRichDecorativeBox</feature>
    <feature>AdfRichPanelSplitter</feature>
    <feature>AdfRichPanelStretchLayout</feature>
    <feature>AdfRichPanelDashboard</feature>
    <feature>AdfPanelDashboardBehavior</feature>
    <feature>AdfDashboardDropTarget</feature>
  </partition>
 
  <partition>
    <partition-name>tabbed</partition-name>
    <feature>AdfUIShowOne</feature>
    <feature>AdfRichPanelTabbed</feature>
  </partition>
 
  <partition>
    <partition-name>table</partition-name>
    <feature>AdfUIIterator</feature>
    <feature>AdfUITable</feature>
    <feature>AdfUITable2</feature>
    <feature>AdfUIColumn</feature>
    <feature>AdfRichColumn</feature>
    <feature>AdfRichTable</feature>
  </partition>
 
  <partition>
    <partition-name>toolbar</partition-name>
    <feature>AdfRichCommandToolbarButton</feature>
    <feature>AdfRichToolbar</feature>
  </partition>
 
  <partition>
    <partition-name>toolbox</partition-name>
    <feature>AdfRichToolbox</feature>
  </partition>
 
  <partition>
    <partition-name>train</partition-name>
    <feature>AdfUIProcess</feature>
    <feature>AdfRichCommandTrainStop</feature>
    <feature>AdfRichTrainButtonBar</feature>
    <feature>AdfRichTrain</feature>
  </partition>
 
  <partition>
    <partition-name>tree</partition-name>
    <feature>AdfUITree</feature>
    <feature>AdfUITreeTable</feature>
    <feature>AdfRichTree</feature>
    <feature>AdfRichTreeTable</feature>
  </partition>
 
  <!--
    Some components which typically do have client-side representation,
    but small enough that we might as well download in a single partition
    in the event that any of these are needed.
  -->
  <partition>
    <partition-name>uncommon</partition-name>
    <feature>AdfRichGoButton</feature>
    <feature>AdfRichIcon</feature>
    <feature>AdfRichImage</feature>
    <feature>AdfRichOutputText</feature>
    <feature>AdfRichPanelGroupLayout</feature>
    <feature>AdfRichSeparator</feature>
    <feature>AdfRichSpacer</feature>
    <feature>AdfRichGoLink</feature>
  </partition>
 
  <partition>
    <partition-name>eum</partition-name>
    <feature>AdfEndUserMonitoring</feature>
  </partition>
 
  <partition>
    <partition-name>ads</partition-name>
    <feature>AdfActiveDataService</feature>
  </partition>
 
  <partition>
    <partition-name>automation</partition-name>
    <feature>AdfAutomationTest</feature>
  </partition>
 
</partitions>

F.2 Samples for Chapter 30, "Using Treemap and Sunburst Components"

Following are code examples for creating treemap and sunburst components.

F.2.1 Sample Code for Treemap and Sunburst Census Data Example

When you create a treemap or sunburst using UI-first development, you can use Java classes and managed beans to define the tree node and tree model, populate the tree with data and add additional methods as needed to configure the treemap or sunburst.

Example F-2 shows a code sample defining the tree node in the census data example. Note that the required settings for label, size, and color are passed in as parameters to the tree node.

Example F-2 Code Sample to Create a Treemap or Sunburst Tree Node

import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
 
public class TreeNode {
  private final String m_text;
  private final Number m_size;
  private final Color m_color;
  private final List<TreeNode> m_children = new ArrayList<TreeNode>();
  
  public TreeNode(String text, Number size, Color color) {
    m_text = text;
    m_size = size;
    m_color = color;
  }
  public String getText() {
    return m_text;
  }
  public Number getSize() {
    return m_size;
  }
  public Color getColor() {
    return m_color;
  }
  public void addChild(TreeNode child) {
    m_children.add(child);
  }
  public void addChildren(List<TreeNode> children) {
    m_children.addAll(children);
  }
  public List<TreeNode> getChildren() {
    return m_children;
  }
  @Override
  public String toString() {
    return m_text + ": " + m_color + " " + Math.round(m_size.doubleValue());
  }
}

To supply data to the treemap or sunburst in UI-first development, add a class or managed bean to your application that extends the tree node in Example F-2 and populates it with data. The class to set up the tree model must be an implementation of the org.apache.myfaces.trinidad.model.TreeModel class. Once the tree model is defined, create a method that implements the org.apache.myfaces.trinidad.model.ChildPropertyTreeModel to complete the tree model.

Example F-3 shows a sample class that sets up the root and child node structure, populates the child levels with data and defines the color and node sizes in the census data example.

Example F-3 Code Sample Creating Census Data Model for Treemap and Sunburst

import java.awt.Color;
 
import java.util.ArrayList;
import java.util.List;
 
import org.apache.myfaces.trinidad.model.ChildPropertyTreeModel;
import org.apache.myfaces.trinidad.model.TreeModel;
 
 
public class CensusData {
 
  public static TreeModel getUnitedStatesData() {
    return getModel(ROOT);
  }
 
  public static TreeModel getRegionWestData() {
    return getModel(REGION_W);
  }
 
  public static TreeModel getRegionNortheastData() {
    return getModel(REGION_NE);
  }
 
  public static TreeModel getRegionMidwestData() {
    return getModel(REGION_MW);
  }
 
  public static TreeModel getRegionSouthData() {
    return getModel(REGION_S);
  }
 
  public static TreeModel getDivisionPacificData() {
    return getModel(DIVISION_P);
  }
 
  private static TreeModel getModel(DataItem rootItem) {
    TreeNode root = getTreeNode(rootItem);
    return new ChildPropertyTreeModel(root, "children");
  }
 
  private static TreeNode getTreeNode(DataItem dataItem)
  {
    // Create the node itself
    TreeNode node = new CensusTreeNode(dataItem.getName(),
                        dataItem.getPopulation(),
                        getColor(dataItem.getIncome(), MIN_INCOME, MAX_INCOME),
                        dataItem.getIncome());
 
    // Create its children
    List<TreeNode> children = new ArrayList<TreeNode>();
    for(DataItem childItem : dataItem.children) {
      children.add(getTreeNode(childItem));
    }
 
    // Add the children and return
    node.addChildren(children);
    return node;
  }
 
  private static Color getColor(double value, double min, double max) {
    double percent = Math.max((value - min) / max, 0);
    if(percent > 0.5) {
      double modifier = (percent - 0.5) * 2;
      return new Color((int)(modifier*102), (int)(modifier*153), (int)(modifier*51));
    }
    else {
      double modifier = percent *2;
      return new Color((int)(modifier*204), (int)(modifier*51), 0);
    }
  }
 
  public static class DataItem {
    private final String name;
    private final int population;
    private final int income;
    private final List<DataItem> children;
 
    public DataItem(String name, int population, int income) {
      this.name = name;
      this.population = population;
      this.income = income;
      this.children = new ArrayList<DataItem>();
    }
 
    public void addChild(DataItem child) {
      this.children.add(child);
    }
 
    public String getName() {
      return name;
    }
 
    public int getPopulation() {
      return population;
    }
 
    public int getIncome() {
      return income;
    }
 
    public List<CensusData.DataItem> getChildren() {
      return children;
    }
  }
 
  private static final int MIN_INCOME = 0;
  private static final int MAX_INCOME = 70000;
 
  private static final DataItem ROOT = new DataItem("United States", 301461533, 51425);
 
  private static final DataItem REGION_NE = new DataItem("Northeast Region", 54906297, 57208);
  private static final DataItem REGION_MW = new DataItem("Midwest Region", 66336038, 49932);
  private static final DataItem REGION_S = new DataItem("South Region", 110450832, 47204);
  private static final DataItem REGION_W = new DataItem("West Region", 69768366, 56171);
 
  private static final DataItem DIVISION_NE = new DataItem("New England", 14315257, 61511);
  private static final DataItem DIVISION_MA = new DataItem("Middle Atlantic", 40591040, 55726);
  private static final DataItem DIVISION_ENC = new DataItem("East North Central", 46277998, 50156);
  private static final DataItem DIVISION_WNC = new DataItem("West North Central", 20058040, 49443);
  private static final DataItem DIVISION_SA = new DataItem("South Atlantic", 57805475, 50188);
  private static final DataItem DIVISION_ESC = new DataItem("East South Central", 17966553, 41130);
  private static final DataItem DIVISION_WSC = new DataItem("West South Central", 34678804, 45608);
  private static final DataItem DIVISION_M = new DataItem("Mountain", 21303294, 51504);
  private static final DataItem DIVISION_P = new DataItem("Pacific", 48465072, 58735);
 
  static {
    // Set up the regions
    ROOT.addChild(REGION_NE);
    ROOT.addChild(REGION_MW);
    ROOT.addChild(REGION_S);
    ROOT.addChild(REGION_W);
 
    // Set up the divisions
    REGION_NE.addChild(DIVISION_NE);
    REGION_NE.addChild(DIVISION_MA);
    REGION_MW.addChild(DIVISION_ENC);
    REGION_MW.addChild(DIVISION_WNC);
    REGION_S.addChild(DIVISION_SA);
    REGION_S.addChild(DIVISION_ESC);
    REGION_S.addChild(DIVISION_WSC);
    REGION_W.addChild(DIVISION_M);
    REGION_W.addChild(DIVISION_P);
 
    // Set up the states
    DIVISION_NE.addChild(new DataItem("Connecticut", 3494487, 67721));
    DIVISION_NE.addChild(new DataItem("Maine", 1316380, 46541));
    DIVISION_NE.addChild(new DataItem("Massachusetts", 6511176, 64496));
    DIVISION_NE.addChild(new DataItem("New Hampshire", 1315419, 63033));
    DIVISION_NE.addChild(new DataItem("Rhode Island", 1057381, 55569));
    DIVISION_NE.addChild(new DataItem("Vermont", 620414, 51284));
 
    DIVISION_MA.addChild(new DataItem("New Jersey", 8650548, 68981));
    DIVISION_MA.addChild(new DataItem("New York", 19423896, 55233));
    DIVISION_MA.addChild(new DataItem("Pennsylvania", 12516596, 49737));
 
    DIVISION_ENC.addChild(new DataItem("Indiana", 6342469, 47465));
    DIVISION_ENC.addChild(new DataItem("Illinois", 12785043, 55222));
    DIVISION_ENC.addChild(new DataItem("Michigan", 10039208, 48700));
    DIVISION_ENC.addChild(new DataItem("Ohio", 11511858, 47144));
    DIVISION_ENC.addChild(new DataItem("Wisconsin", 5599420, 51569));
 
    DIVISION_WNC.addChild(new DataItem("Iowa", 2978880, 48052));
    DIVISION_WNC.addChild(new DataItem("Kansas", 2777835, 48394));
    DIVISION_WNC.addChild(new DataItem("Minnesota", 5188581, 57007));
    DIVISION_WNC.addChild(new DataItem("Missouri", 5904382, 46005));
    DIVISION_WNC.addChild(new DataItem("Nebraska", 1772124, 47995));
    DIVISION_WNC.addChild(new DataItem("North Dakota", 639725, 45140));
    DIVISION_WNC.addChild(new DataItem("South Dakota", 796513, 44828));
 
    DIVISION_SA.addChild(new DataItem("Delaware", 863832, 57618));
    DIVISION_SA.addChild(new DataItem("District of Columbia", 588433, 56519));
    DIVISION_SA.addChild(new DataItem("Florida", 18222420, 47450));
    DIVISION_SA.addChild(new DataItem("Georgia", 9497667, 49466));
    DIVISION_SA.addChild(new DataItem("Maryland", 5637418, 69475));
    DIVISION_SA.addChild(new DataItem("North Carolina", 9045705, 45069));
    DIVISION_SA.addChild(new DataItem("South Carolina", 4416867, 43572));
    DIVISION_SA.addChild(new DataItem("Virginia", 7721730, 60316));
    DIVISION_SA.addChild(new DataItem("West Virginia", 1811403, 37356));
 
    DIVISION_ESC.addChild(new DataItem("Alabama", 4633360, 41216));
    DIVISION_ESC.addChild(new DataItem("Kentucky", 4252000, 41197));
    DIVISION_ESC.addChild(new DataItem("Mississippi", 2922240, 36796));
    DIVISION_ESC.addChild(new DataItem("Tennessee", 6158953, 42943));
 
    DIVISION_WSC.addChild(new DataItem("Arkansas", 2838143, 38542));
    DIVISION_WSC.addChild(new DataItem("Louisiana", 4411546, 42167));
    DIVISION_WSC.addChild(new DataItem("Oklahoma", 3610073, 41861));
    DIVISION_WSC.addChild(new DataItem("Texas", 23819042, 48199));
 
    DIVISION_M.addChild(new DataItem("Arizona", 6324865, 50296));
    DIVISION_M.addChild(new DataItem("Colorado", 4843211, 56222));
    DIVISION_M.addChild(new DataItem("Idaho", 1492573, 46183));
    DIVISION_M.addChild(new DataItem("Montana", 956257, 43089));
    DIVISION_M.addChild(new DataItem("Nevada", 2545763, 55585));
    DIVISION_M.addChild(new DataItem("New Mexico", 1964860, 42742));
    DIVISION_M.addChild(new DataItem("Utah", 2651816, 55642));
    DIVISION_M.addChild(new DataItem("Wyoming", 523949, 51990));
 
    DIVISION_P.addChild(new DataItem("Alaska", 683142, 64635));
    DIVISION_P.addChild(new DataItem("California", 36308527, 60392));
    DIVISION_P.addChild(new DataItem("Hawaii", 1280241, 64661));
    DIVISION_P.addChild(new DataItem("Oregon", 3727407, 49033));
    DIVISION_P.addChild(new DataItem("Washington", 6465755, 56384));
  }
 
  public static class CensusTreeNode extends TreeNode {
    private int income;
 
    public CensusTreeNode(String text, Number size, Color color, int income) {
      super(text, size, color);
      this.income = income;
    }
 
    public int getIncome() {
      return income;
    }
  }
}

Finally, to complete the tree model in UI-first development, add a managed bean to your application that references the class or bean that contains the data and, optionally, add any other methods to customize the treemap or sunburst.

Example F-4 shows a code sample that will instantiate the census treemap and populate it with census data. The example also includes a sample method (convertToString) that will convert the treemap node's row data to a string for label display.

Example F-4 Managed Bean Example to Set Census Data Treemap

import org.apache.myfaces.trinidad.component.UIXHierarchy;
import org.apache.myfaces.trinidad.model.RowKeySet;
import org.apache.myfaces.trinidad.model.TreeModel;
import oracle.adf.view.faces.bi.component.treemap.UITreemap;
 
public class SampleTreemap {
  // Data Model Attrs
  private TreeModel currentModel;
  private final CensusData censusData = new CensusData();
  private String censusRoot = "United States";
  private UITreemap treemap;
 
  public TreeModel getCensusRootData() {
    return censusData.getUnitedStatesData();
  }
  public TreeModel getCensusData() {
    if ("West Region".equals(censusRoot))
      return censusData.getRegionWestData();
    else if ("South Region".equals(censusRoot))
      return censusData.getRegionSouthData();
    else if ("Midwest Region".equals(censusRoot))
      return censusData.getRegionMidwestData();
    else if ("Northeast Region".equals(censusRoot))
      return censusData.getRegionNortheastData();
    else if ("Pacific Division".equals(censusRoot))
      return censusData.getDivisionPacificData();
    else
      return censusData.getUnitedStatesData();
  }
  public TreeModel getData() {
    // Return cached data model if available
    if(currentModel != null)
      return currentModel;
    currentModel = getCensusData();
    return currentModel;
  }
  public void setCensusRoot(String censusRoot) {
    this.censusRoot = censusRoot;
  }
  public String getCensusRoot() {
    return censusRoot;
  }
  //Converts the rowKeySet into a string of node text labels.
  public static String convertToString(RowKeySet rowKeySet, UIXHierarchy hierarchy) {
    StringBuilder s = new StringBuilder();
    if (rowKeySet != null) {
      for (Object rowKey : rowKeySet) {
        TreeNode rowData = (TreeNode)hierarchy.getRowData(rowKey);
        s.append(rowData.getText()).append(", ");
      }
      // Remove the trailing comma
      if (s.length() > 0)
        s.setLength(s.length() - 2);
    }
    return s.toString();
  }
  public void setTreemap(UITreemap treemap) {
        this.treemap = treemap;
  }
  public UITreemap getTreemap() {
        return treemap;
  }
}

The code to set up the sunburst census sample is nearly identical since both components use the same tree model. See Section F.2.2, "Code Sample for Sunburst Managed Bean" for an example.

F.2.2 Code Sample for Sunburst Managed Bean

The following code sample instantiates the census sunburst and populates it with census data. The example also includes a sample method (convertToString) that will convert the sunburst node's row data to a string for label display.

Example F-5 Managed Bean Example to Set Census Data Sunburst

import oracle.adf.view.faces.bi.component.sunburst.UISunburst;
import org.apache.myfaces.trinidad.component.UIXHierarchy;
import org.apache.myfaces.trinidad.model.RowKeySet;
import org.apache.myfaces.trinidad.model.TreeModel;
 
public class SunburstSample {
  // Components
  private UISunburst sunburst;
  // Attributes
  private TreeModel currentModel;
  private final CensusData censusData = new CensusData();
  private String censusRoot = "United States";
  
  public TreeModel getCensusRootData() {
    return censusData.getUnitedStatesData();
  }
  public TreeModel getCensusData() {
    if ("West Region".equals(censusRoot))
      return censusData.getRegionWestData();
    else if ("South Region".equals(censusRoot))
      return censusData.getRegionSouthData();
    else if ("Midwest Region".equals(censusRoot))
      return censusData.getRegionMidwestData();
    else if ("Northeast Region".equals(censusRoot))
      return censusData.getRegionNortheastData();
    else if ("Pacific Division".equals(censusRoot))
      return censusData.getDivisionPacificData();
    else
      return censusData.getUnitedStatesData();
  }
  public TreeModel getData() {
    // Return cached data model if available
    if(currentModel != null)
      return currentModel;
    currentModel = getCensusData();
    return currentModel;
  }
  public void setCensusRoot(String censusRoot) {
    this.censusRoot = censusRoot;
  }
  public String getCensusRoot() {
    return censusRoot;
  }
  public static String convertToString(RowKeySet rowKeySet, UIXHierarchy hierarchy) {
    StringBuilder s = new StringBuilder();
    if (rowKeySet != null) {
      for (Object rowKey : rowKeySet) {
        TreeNode rowData = (TreeNode)hierarchy.getRowData(rowKey);
        s.append(rowData.getText()).append(", ");
      }
      // Remove the trailing comma
      if (s.length() > 0)
        s.setLength(s.length() - 2);
    }
    return s.toString();
  }  
  public void setSunburst(UISunburst sunburst) {    
    this.sunburst = sunburst;
  }
  public UISunburst getSunburst() {
    return sunburst;
  }
}