title: Export full tree to excel
body: <p>I'm trying to Export a full tree to Excel and I'm having a problem.</p>
  
  <ul>
  <li>First:</li>
  </ul>
  
  <p>My tree has as least 5 levels, but I can only print two of them. I don't know why it won't print the rest of the children.</p>
  
  <ul>
  <li>Second:</li>
  </ul>
  
  <p>If a new level is added I don't wan't to re-write code. Is there any recursive solution to do it? (Mainly because my export method is way too big already)</p>
  
  <p>Export method:</p>
  
  <pre><code>public static void exportDataDrillDownParamComercial(FacesContext facesContext, OutputStream outputStream, RichTreeTable tree) throws IOException {
  BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8")); 
  CollectionModel treeModel = (CollectionModel) tree.getValue();
  JUCtrlHierBinding treeBinding = (JUCtrlHierBinding) treeModel.getWrappedData();
  List&lt;JUCtrlHierNodeBinding&gt; treeList = treeBinding.getChildren();
  writer.write("Estrutura Comercial");writer.write(",");
  writer.write("Estrutura Operacional Filtrada");writer.write(",");
  writer.write("STK# Inicial (D-1)");writer.write(",");
  writer.write("STK$ Inicial (D-1)"); writer.write(",");
  writer.write("ROT Dias Inicial (D-1)");writer.write(",");
  writer.write("MDQ% Vigor");writer.write(",");
  writer.write("Presentation Stock");writer.write(",");
  writer.write("MDQval Vigor");writer.write(",");
  writer.write("VND ENA"); writer.write(",");
  writer.write("VND REG U1S");writer.write(",");
  writer.write("MDQval Novo");writer.write(",");
  writer.write("ROT MDQ");writer.write(",");
  writer.write("MDQ% Automático");writer.write(",");
  writer.write("SS Vigor"); writer.write(",");
  writer.write("FORECAST 2S");writer.write(",");
  writer.write("VNDREG U2S");writer.write(",");
  writer.write("IPSS% Automático");writer.write(",");
  writer.write("SS Automático");writer.write(",");
  writer.write("MDQ Rel. Automático");writer.write(",");
  writer.write("MDQ% Min. Automático"); writer.write(",");
  writer.write("Var. ROT MDQ");writer.write(",");
  writer.write("Validade Var. ROT MDQ");writer.write(",");
  writer.write("STK # Final");writer.write(",");
  writer.write("STK $ Final");writer.write(",");
  writer.write("ROT Dias Final");writer.write(",");
  writer.write("MDQ% Final");writer.write(",");
  writer.write("IPSS% Final");writer.write(",");
  writer.write("SS Final");writer.write(",");
  writer.write("MDQ Rel. Final");writer.write(",");
  writer.write("MDQ% Mínimo Final");writer.write(",");            
  writer.write("Data de Efetivação");writer.write(",");
  writer.write("Var ROT Dias Automático");writer.write(",");
  writer.write("Var STK # Automático");writer.write(",");
  writer.write("Var STK # % Automático");writer.write(",");
  writer.write("Var STK $ Automático");writer.write(",");
  writer.write("Var STK $ % Automático");writer.write(",");
  writer.write("Var MDQ% Automático");writer.write(",");
  writer.write("Var ROT Dias Final");writer.write(",");
  writer.write("Var STK # Final");writer.write(",");
  writer.write("Var STK # % Final");writer.write(",");
  writer.write("Var STK $ Final");writer.write(",");
  writer.write("Var STK $ % Final");writer.write(",");
  writer.write("Var MDQ% Final");writer.write(",");
  writer.newLine();
  
  for (int i = 0; i &lt; treeList.size(); i++) {
      JUCtrlHierNodeBinding treeNode = treeList.get(i);
      Object[] treeAttrList = treeNode.getAttributes();
      for (int m = 0; m &lt; treeAttrList.length ; m++) {
          Object attr = treeAttrList[m];
          if (attr instanceof java.lang.Long) {writer.write(((Long)attr).toString()); writer.write(";"); }
          if (attr instanceof java.lang.String) {writer.write(((String)attr)); writer.write(";"); }
      }
      writer.newLine();
      List&lt;JUCtrlHierNodeBinding&gt; subList = treeNode.getChildren();
      if(subList!=null) {
          for (int j = 0; j &lt; subList.size(); j++) {
              JUCtrlHierNodeBinding subNode = subList.get(j);
              Object[] subAttrList = subNode.getAttributes();
              writer.write(";");writer.write(";");writer.write(";");writer.write(";");
  
              for (int n = 0; n &lt; subAttrList.length ; n++) {
                  Object subAttr = subAttrList[n];
                  if(subAttr instanceof java.lang.Long) { writer.write(((Long)subAttr).toString()); writer.write(";"); }
                  if(subAttr instanceof java.lang.String) { writer.write(((String)subAttr)); writer.write(";"); }
                  if(subAttr instanceof oracle.jbo.domain.Date) { writer.write(((oracle.jbo.domain.Date)subAttr).stringValue()); writer.write(";"); }             
              }
              writer.newLine();               
          }
      }
      writer.newLine();
  }
  writer.flush();
  }
  </code></pre>