Search code examples
javacontainersvaadinvaadin7

How to get the item ID in vaadin


Good day everyone! I have a HierarchicalContainer below:

contFinalGrade= new HierarchicalContainer();
        contFinalGrade.addContainerProperty("index", Integer.class, 0);
        contFinalGrade.addContainerProperty("subCode", String.class, "");
        contFinalGrade.addContainerProperty("courseId", String.class, "");
        contFinalGrade.addContainerProperty("parentCourseId", String.class, "");
        contFinalGrade.addContainerProperty("subName", String.class, "");
        contFinalGrade.addContainerProperty("term", String.class, "");
        contFinalGrade.addContainerProperty("studyPoints", BigDecimal.class, null);
        contFinalGrade.addContainerProperty("grade", String.class, "");

and I add items by using the code below:

Item newItem = contFinalGrade.getItem(contFinalGrade.addItem());

I'm wondering how to get the itemId using parentCourseId. I need to get it because I need to set the parent of some items. Thanks!


Solution

  • Maybe this is what you are looking for:

    List<Object> id = new ArrayList<Object>();
    
    List<Item> newItem=new ArrayList<Item>();
    
    //Do this on a button click or something maybe  
    id.add(contFinalGrade.addItem()); 
    
    //Create Items with those ids and get your property
    for(int i=0;i<id.size();i++){
    newItem.add(contFinalGrade.getItem(id.get(i)));
    
    newItem.get(i).getItemProperty("parentCourseId");