Tree setParent by ItemId doesn't work.

I want to dynamically add Items to a tree.

I use a Hierarchial Container which contains my data. To set my parents I use the generated ItemId.
But the Hierarchy is wrong!

My TreeComponent looks like:

public class TransaktionsTree extends Tree {

    private Transaktion transaktion;
    private int aenderungen = 1;

    private HierarchicalContainer container = new HierarchicalContainer();
    public TransaktionsTree() {}
    public TransaktionsTree(Transaktion transaktion) {
        this.transaktion = transaktion;

        for(Partner partner : transaktion.getPartner()) {
            String partnerString = "Partner: " + partner.getId();
            Object treePartner = container.addItem(partnerString);

            for(Aenderung aenderung : partner.getAenderung()) {
                String aenderungsidString = "Änderungs NR. " + aenderungen ;
                Object treeAenderung = container.addItem(aenderungsidString);
                container.setParent(treeAenderung, treePartner);

                for(Feld feld : aenderung.getFeld()) {
                    String feldString = "Feld: " + feld.getName();
                    Object treeFeld = container.addItem(feldString);
                    container.setParent(treeFeld, treeAenderung);

                    boolean felderVorhanden = false;

                        if (feld.getAlt().length() != 0) {
                            String alterWertString = "Alter Wert: " + feld.getAlt();
                            Object treeAlterWert = container.addItem(alterWertString);
                            container.setParent(treeAlterWert, treeFeld);
                            container.setChildrenAllowed(alterWertString, false);
                            felderVorhanden = true;

                        if (feld.getNeu().length() != 0) {
                            String neuerWertString = "Neuer Wert: " + feld.getNeu();
                            Object treeNeuerWert = container.addItem(neuerWertString);
                            container.setParent(treeNeuerWert, treeFeld);
                            container.setChildrenAllowed(neuerWertString, false);
                            felderVorhanden = true;

                    container.setChildrenAllowed(treeFeld, felderVorhanden);
//                    container.expandItemsRecursively(treeFeld);
                aenderungen ++;
//            container.expandItem(partnerString);

Can anyone help me to make the hierarchy correct!?
Thanks in advance.


In setParent you have to pass your itemId :

container.setParent(aenderungsidString, partnerString); instead of

container.setParent(treeAenderung, treePartner); Julie

Well I tried that before. But these Strings musn’t be unique. So the hierarchy still is wrong.

So you have to create an object with your String into and add it to your tree.

thank you very much! I implemented a simple pojo and now it works, since there is an object registered in the memory.