primefaces dynamic tieredMenu
<p>I'm use Primefaces 3.3 and I want read submenus and items from database.<br>
This is my menu :</p>

<pre><code>-network &gt;
        -radioChannel &gt;  regChannel
       - station
-userGroup &gt; 
        -users &gt; 
                  register
                  manager
-operators &gt;
                 opNetwork
</code></pre>

<p>note: it's dynamic and submenus and items is variable </p>

<p>and this is my Bean :</p>

<pre><code>@ManagedBean

@ViewScoped
public class menuBean implements Serializable{


private MenuModel model;

public menuBean() {
    model = new DefaultMenuModel();

    //First submenu
    Submenu submenu = new Submenu();
    submenu.setLabel("network");
            Submenu submenu1=new Submenu();
            submenu1.setLabel("radioChannel");
            submenu.getChildren().add(submenu1);
    MenuItem item = new MenuItem();
    item.setValue("regChannel");
    item.setUrl("#");
    submenu1.getChildren().add(item);
            item = new MenuItem();
    item.setValue("station");
    item.setUrl("#");
            submenu.getChildren().add(item);
    model.addSubmenu(submenu);

    //Second submenu
    submenu = new Submenu();
    submenu.setLabel("userGroup");
    submenu1=new Submenu();
            submenu1.setLabel("users");
            submenu.getChildren().add(submenu1);
    item = new MenuItem();
    item.setValue("register");
    item.setUrl("#");
    submenu1.getChildren().add(item);
            item = new MenuItem();
    item.setValue("manager");
    item.setUrl("#");
    submenu1.getChildren().add(item);
            model.addSubmenu(submenu);

            //3 sunmenu 
            submenu = new Submenu();
    submenu.setLabel("operators");
            item = new MenuItem();
    item.setValue("opNetwork");
    item.setUrl("#");
    submenu.getChildren().add(item);
    model.addSubmenu(submenu);
}

public MenuModel getModel() {
    return model;
}   
  }
</code></pre>

<p>its work great!!!<br>
Now I want read all names and number of submenus and items from database because its variable and the System Administrator can generate optional menu with enter submenus and items name in Related form and fill table in database, then fetch it in myBean for generate optional menu.
So all the above code should be changed and dynamic generated,I may have two or ten submenus or items that read the database.
this is my table:</p>

<pre>
    id       caption                    url         parentId
     1     network                        #              0            
     2     userGroup                      #              0
     3     operators                      #              0
     4     radioChannel                   #              1
     5     station              ./pages/station          1
     6     users                          #              2
     7     registerChannel      ./pages/radio            4
     8     register             ./pages/regUsers         6
     9     manager              ./pages/mngUsers         6
     10    opNetwork            ./pages/opNet            3
</pre>

<p>How do I implement it with a recursive function? that Identify the items and their parent submenus,The similar tree Structure,Anyone has done similar work? </p>
