Tree leaves with duplicate captions ...

Hello,

I am relatively new to Vaadin and I am sure I am missing something. The ‘problem’ I am having is that several of my branches have leaves with duplicate captions, but only the last duplicate leave is shown. The backing tree objects are POJOs where I have set the

toString()

function generate the item’s unique id.

What I am expecting to see:
[font=courier new]
Policy A

  1. Recommendations
    1.1 Account Policies
    1.1.1 Enforce Password Histroy
    • Password History Memory is Equal to 24
      Policy B
  2. Recommendations
    1.1 Account Policies
    1.1.1 Enforce Password Histroy
    • Password History Memory is Equal to 24
      [/font]

What I am actually seeing:
[font=courier new]
Policy A

  1. Recommendations
    1.1 Account Policies
    1.1.1 Enforce Password Histroy

Policy B

  1. Recommendations
    1.1 Account Policies
    1.1.1 Enforce Password Histroy
    • Password History Memory is Equal to 24
      [/font]

I have confirmed that each item does have a unique id, the only thing that is the same is the caption, which doesn’t make sense. I have also tested building my tree where there were no duplicated captions and all the leaves were displayed as expected.

The code I am using to add the leaves is:


tree.addItem(tmpPolicyTest);
tree.setItemCaption(tmpPolicyTest, tmpPolicyTest.getName());
tree.setParent(tmpPolicyTest, parentItem);
tree.setChildrenAllowed(tmpPolicyTest, false);

Thanks in advance for any insight!

Sean

Hi,

I suspect your POJO does not properly implement equals and hashcode methods. These are the only methods used by vaadin to identify different itemIds, so please make sure that the two items with the caption “* Password History Memory is Equal to 24” do
not
equal each other (or return the same hashcode) when compared with the equals method.

Thanks Teppo,

That did the trick, my equals() method was incorrect. Once i got that sorted out, everything worked as expected!