Treetable and POJO

Hi
I am trying to create my first treetable. I have two tables in the database i.e. Address and Country. I want to set Country as parent and address as child node of the treetable. I understand I have to link parent field with child but not sure where I am missing what. Currently the following code displayes the address table with leaf but actually it looks like a plan table. Thanks for your help.

@CDIView("treetable")
public class TreeTableView extends MVerticalLayout implements View {

    @Inject
    AddressFacade af;
    @Inject
    CountryFacade cf;

    TreeTable ttable;

    @PostConstruct
    public void initComponent() {

        //---------------------------------
        ttable = new TreeTable("My TreeTable");

        final BeanItemContainer<Address> containerChild = new BeanItemContainer<Address>(Address.class);
        final BeanItemContainer<Country> containerParent = new BeanItemContainer<Country>(Country.class);

        containerChild.addAll(af.findAll());
        containerParent.addAll(cf.findAll());

        final ContainerHierarchicalWrapper wrapper = new ContainerHierarchicalWrapper(containerChild);

        wrapper.setParent(containerChild, containerParent);
        
        ttable.setImmediate(true);
        ttable.setWidth("100%");
        ttable.setContainerDataSource(wrapper);

        // Expand the tree
        ttable.setCollapsed(2, false);
        for (Object itemId : ttable.getItemIds()) {
            ttable.setCollapsed(itemId, false);
        }

        ttable.setPageLength(ttable.size());

        addComponent(ttable);

        //--------------------------
        addLayoutClickListener(new LayoutEvents.LayoutClickListener() {

            @Override
            public void layoutClick(LayoutEvents.LayoutClickEvent event) {

            }
        });
    }

    @Override
    public void enter(ViewChangeListener.ViewChangeEvent event) {
    }

}

Hi
I am still waiting for help from anyone. meanwhile, I have addedd little more code the outcome is still a table with leaf symble (as attached).

[code]
@CDIView(“treetable”)
public class TreeTableView extends MVerticalLayout implements View {

@Inject
AddressFacade af;
@Inject
CountryFacade cf;

TreeTable ttable;

 private Set<Country> country = new HashSet();

@PostConstruct
public void initComponent() {

    final BeanItemContainer<Address> containerChild = new BeanItemContainer<Address>(Address.class);
    final BeanItemContainer<Country> containerParent = new BeanItemContainer<Country>(Country.class);

    containerChild.addAll(af.findAll());
    containerParent.addAll(cf.findAll());

    ContainerHierarchicalWrapper wrapper = new ContainerHierarchicalWrapper(containerChild);

    for (Address addr : af.findAll()) {
        for (Country coun : cf.findAll()) {
            if(addr.getCountry().getCountryname().equalsIgnoreCase(coun.getCountryname())){
                wrapper.setParent(addr, coun);
            }
        }        
    }        

// List a = (List) (Address) af.findAll();
// List a2 = (List) (Address) af.findAll();
// for (Address addr : a) {
// for (Address addr2 : a2){
// if(addr.getCity().equalsIgnoreCase(addr2.getCity())){
// wrapper.setParent(addr, addr);
// return;
// }
// wrapper.setParent(addr, “”);
// }
// }

    ttable = new TreeTable("My TreeTable");
    
    ttable.setImmediate(true);
    ttable.setWidth("100%");
    ttable.setContainerDataSource(wrapper);
    
  //  ttable.setVisibleColumns("country", "street","city");
  //  ttable.setColumnHeaders("country", "street","city");
   // ttable.setItemCaptionMode(Tree.ITEM_CAPTION_MODE_PROPERTY);

    
    // Expand the tree
    ttable.setCollapsed(2, false);
    for (Object itemId : ttable.getItemIds()) {
        ttable.setCollapsed(itemId, false);
    }

    ttable.setPageLength(ttable.size());

    addComponent(ttable);

    //--------------------------
    addLayoutClickListener(new LayoutEvents.LayoutClickListener() {

        @Override
        public void layoutClick(LayoutEvents.LayoutClickEvent event) {

        }
    });
}

@Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
}

}
[/code]Thanks for your help.
17620.png

You are trying to combine two different data types in the Table; that won’t work, at least not this way.

First, when you call setParent(), the new parent must already be inside the container. In you case it isn’t, since the child container doesn’t know about the parent container.

Secondly, adding Address and Country object to the same BeanItemContainer is not possible, since they use incompatible types (bean classes).

And lastly, any container you give to the Table needs to have the same columns for each row. In your case, since you have two different data types, you will need to match the columns yourself. You do that not by using BeanItemContainer, but creating a HierarchicalContainer, adding all columns you are going to need (addContainerProperty), adding each row (both Addresses and Countries), and the fixing the parent-child relations (container.setParent(adress, country)) for each adress. See the book of Vaadin,
https://vaadin.com/book/-/page/datamodel.container.html
. A lot more code than using BeanItemContainer, but there isn’t really any other way, sorry.

Hi Thomas
Thanks for your reply with details. I am new in vaadin and still not successful, please don’t mind. I have modified the code as below and having the exceptions. I am also appending herewith the entities

Modified view

@CDIView("treetable")
public class TreeTableView extends MVerticalLayout implements View {

    @Inject
    AddressFacade af;
    @Inject
    CountryFacade cf;

    TreeTable ttable;

     private Set<Country> country = new HashSet();

    @PostConstruct
    public void initComponent() {

     
        
        List<Address> a = (List) (Address) af.findAll();
        List<Address> a2 = (List) (Address) af.findAll();
        
      HierarchicalContainer container = new HierarchicalContainer();  
      
        // Initialize the container as required by the container type
        container.addContainerProperty("city", String.class, null);
        container.addContainerProperty("street", String.class, 0);
        container.addContainerProperty("countryId", String.class, 0);
        container.addContainerProperty("countryName", String.class, 0);
        container.addContainerProperty("country", String.class, 0);
        for (Address addr : a) {
            for (Address addr2 : a2){
                if(addr.getCity().equalsIgnoreCase(addr2.getCity())){
                    // Create an item
                    Object itemId = container.addItem();
                    // Get the item object
                    container.getContainerProperty(itemId, "city").setValue(addr.getCity().toString());
                    container.getContainerProperty(itemId, "street").setValue(addr.getStreet().toString());
                    container.getContainerProperty(itemId, "country").setValue(addr2.getCountry());
                    //container.setParent(container.getItem("street"), container.getItem("country"));
                    container.setParent(addr,addr2);
                    return;
                }
                container.setParent(addr, "");
                
            }        
        }        
        
        ttable.setContainerDataSource(container);
        
        // Expand the tree
        ttable.setCollapsed(2, false);
        for (Object itemId : ttable.getItemIds()) {
            ttable.setCollapsed(itemId, false);
        }

        ttable.setPageLength(ttable.size());

        addComponent(ttable);

        //--------------------------
        addLayoutClickListener(new LayoutEvents.LayoutClickListener() {

            @Override
            public void layoutClick(LayoutEvents.LayoutClickEvent event) {

            }
        });
    }

    @Override
    public void enter(ViewChangeListener.ViewChangeEvent event) {
    }

}

Exceptions:

Severe: org.jboss.weld.exceptions.WeldException: WELD-000049: Unable to invoke public void com.inteacc.view.TreeTableView.initComponent() on com.inteacc.view.TreeTableView@3b6f5a92 at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.invokeMethods(DefaultLifecycleCallbackInvoker.java:100) at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.postConstruct(DefaultLifecycleCallbackInvoker.java:81) at org.jboss.weld.injection.producer.BasicInjectionTarget.postConstruct(BasicInjectionTarget.java:114) at org.jboss.weld.injection.producer.BeanInjectionTarget.postConstruct(BeanInjectionTarget.java:70) at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:153) at com.vaadin.cdi.internal.UIBeanStore.getBeanInstance(UIBeanStore.java:53) at com.vaadin.cdi.internal.UIScopedContext.get(UIScopedContext.java:105) at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:740) at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:760) at org.jboss.weld.util.ForwardingBeanManager.getReference(ForwardingBeanManager.java:61) at org.jboss.weld.bean.builtin.BeanManagerProxy.getReference(BeanManagerProxy.java:78) at com.vaadin.cdi.CDIViewProvider.getView(CDIViewProvider.java:213) at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:513) at com.inteacc.util.ViewMenu.lambda$getButtonFor$cbcad451$1(ViewMenu.java:73) at com.inteacc.util.ViewMenu$$Lambda$2/1510522371.buttonClick(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508) at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198) at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161) at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:979) at com.vaadin.ui.Button.fireClick(Button.java:393) at com.vaadin.ui.Button$1.click(Button.java:57) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:168) at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:118) at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:287) at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:180) at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:93) at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41) at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1406) at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:305) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282) at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167) at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201) at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175) at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235) at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201) at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133) at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112) at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561) at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.invokeMethods(DefaultLifecycleCallbackInvoker.java:98) ... 65 more Caused by: java.lang.ClassCastException: java.util.Vector cannot be cast to com.inteacc.entity.Address at com.inteacc.view.TreeTableView.initComponent(TreeTableView.java:112) ... 70 more Entity beans

[code]
@Entity
@Table(name = “ADDRESS”)
@XmlRootElement
@NamedQueries({
@NamedQuery(name = “Address.findAll”, query = “SELECT a FROM Address a”),
@NamedQuery(name = “Address.findById”, query = “SELECT a FROM Address a WHERE a.id = :id”),
@NamedQuery(name = “Address.findByCity”, query = “SELECT a FROM Address a WHERE a.city = :city”),
@NamedQuery(name = “Address.findByCountry”, query = “SELECT a FROM Address a WHERE a.country = :country”),
@NamedQuery(name = “Address.findByStreet”, query = “SELECT a FROM Address a WHERE a.street = :street”)})
public class Address implements Serializable {
private static final long serialVersionUID = 1L;
// @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
@Id
@Basic(optional = false)
@NotNull
@Column(name = “ID”)
@GeneratedValue(strategy=GenerationType.AUTO)
private BigDecimal id;
@JoinColumn(name = “COUNTRY_ID”, referencedColumnName = “ID”)
@ManyToOne
private Country country;
@Size(max = 255)
@Column(name = “CITY”)
private String city;
@Size(max = 255)
@Column(name = “STREET”)
private String street;

public Address() {
}

public Address(BigDecimal id) {
    this.id = id;
}

public BigDecimal getId() {
    return id;
}

public void setId(BigDecimal id) {
    this.id = id;
}

public String getCity() {
    return city;
}

public void setCity(String city) {
    this.city = city;
}


public String getStreet() {
    return street;
}

public void setStreet(String street) {
    this.street = street;
}

public Country getCountry() {
    return country;
}

public void setCountry(Country country) {
    this.country = country;
}



@Override
public int hashCode() {
    int hash = 0;
    hash += (id != null ? id.hashCode() : 0);
    return hash;
}

@Override
public boolean equals(Object object) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof Address)) {
        return false;
    }
    Address other = (Address) object;
    if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
        return false;
    }
    return true;
}

@Override
public String toString() {
    return "com.inteacc.entity.Address[ id=" + id + " ]

";

}

}
[/code][code]
@Entity
@Table(name = “COUNTRY”)
@XmlRootElement
@NamedQueries({
@NamedQuery(name = “Country.findAll”, query = “SELECT c FROM Country c”),
@NamedQuery(name = “Country.findById”, query = “SELECT c FROM Country c WHERE c.id = :id”),
@NamedQuery(name = “Country.findByCountryname”, query = “SELECT c FROM Country c WHERE c.countryname = :countryname”)})
public class Country implements Serializable {
private static final long serialVersionUID = 1L;
// @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
@Id
@Basic(optional = false)
@NotNull
@Column(name = “ID”)
@GeneratedValue(strategy=GenerationType.AUTO)
private BigDecimal id;
@Size(max = 255)
@Column(name = “COUNTRYNAME”)
private String countryname;
// @OneToMany(mappedBy = “countryId”)
// private Collection addressCollection;

public Country() {
}

public Country(BigDecimal id) {
    this.id = id;
}

public BigDecimal getId() {
    return id;
}

public void setId(BigDecimal id) {
    this.id = id;
}

public String getCountryname() {
    return countryname;
}

public void setCountryname(String countryname) {
    this.countryname = countryname;
}


@Override
public int hashCode() {
    int hash = 0;
    hash += (id != null ? id.hashCode() : 0);
    return hash;
}

@Override
public boolean equals(Object object) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof Country)) {
        return false;
    }
    Country other = (Country) object;
    if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
        return false;
    }
    return true;
}

@Override
public String toString() {
    //return "com.inteacc.entity.Country[ id=" + id + " ]

";
return getCountryname();
}

}
[/code]Thanks for any help.

This obviously won’t work:

List<Address> a = (List) (Address) af.findAll(); As the stacktrace says:

Caused by: java.lang.ClassCastException: java.util.Vector cannot be cast to com.inteacc.entity.Address

Thanks Thomas. You are so helpful. Would you please help a bit more what I am missing here.

OK, lets take a look… Now you loop over the adresses, but not the countries: for (Address addr : a) { for (Address addr2 : a2){ What I was thinking was to do this:

//create container
//add container properties

//add items
for(Country c )
    //add each country

for(Address a)
   //add each address
   //call setParent(a, c)

That should give you what you need.

Thank you Thomas. It seems i am almost there but still have a glitz somewhere. While I run the following modified codes, getting no good result!!

[code]

    ArrayList<Address> addr =  new ArrayList<Address>();
    ArrayList<Country> ctry =  new ArrayList<Country>();

    addr.addAll(af.findAll());
    ctry.addAll(cf.findAll());
    
    //Create container
    HierarchicalContainer container = new HierarchicalContainer();  
  
    // Initialize the container as required by the container type
    container.addContainerProperty("id", BigDecimal.class, null);
    container.addContainerProperty("countryName", String.class, null);
    container.addContainerProperty("id", Integer.class, null);
    container.addContainerProperty("city", String.class, null);
    container.addContainerProperty("street", String.class, null);
    container.addContainerProperty("countryId", BigDecimal.class, null);

System.out.println("i am here : country size: "+ctry.size());
System.out.println("i am here : address size: "+addr.size());

    for (Country c : ctry) {
        
        // Create an item
        Object itemId = container.addItem();
        container.getContainerProperty(itemId, "id").setValue(c.getId());
        container.getContainerProperty(itemId, "countryName").setValue(c.getCountryname());

        for (Address a : addr){
            if(c.getCountryname().equalsIgnoreCase(a.getCountry().getCountryname())){
                // Get the item object
                container.getContainerProperty(itemId, "id").setValue(a.getId());
                container.getContainerProperty(itemId, "city").setValue(a.getCity());
                container.getContainerProperty(itemId, "street").setValue(a.getStreet());
                container.getContainerProperty(itemId, "countryId").setValue(a.getCountry().getId());

System.out.println("i am here : country: “+a.getCountry().getCountryname()+” city: "+a.getCity());
container.setParent(a,c);

            }
        }        
    }        
    
    ttable.setContainerDataSource(container);

[/code]Exceptions:

Warning:   
=================================================================
Vaadin is running in DEBUG MODE.
Add productionMode=true to web.xml to disable debug features.
To show debug window, add ?debug to your application URL.
=================================================================
Info:   New BeanStoreContainer created
Warning:   An already registered connector was registered again: MVerticalLayout (47)
Warning:   An already registered connector was registered again: FormLayout (48)
Warning:   An already registered connector was registered again: MTextField (49)
Warning:   An already registered connector was registered again: MTextField (50)
Warning:   An already registered connector was registered again: MTextField (51)
Warning:   An already registered connector was registered again: MTextField (52)
Warning:   An already registered connector was registered again: MHorizontalLayout (53)
Warning:   An already registered connector was registered again: PrimaryButton (54)
Warning:   An already registered connector was registered again: MButton (55)
Info:   i am here : country size: 16
Info:   i am here : address size: 27
Info:   i am here : country: Canada city: Toronto
Info:   i am here : country: Canada city: Vancouver
Severe:   org.jboss.weld.exceptions.WeldException: WELD-000049: Unable to invoke public void com.my.view.TreeTableView.initComponent() on com.my.view.TreeTableView@4d28c60
    at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.invokeMethods(DefaultLifecycleCallbackInvoker.java:100)
    at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.postConstruct(DefaultLifecycleCallbackInvoker.java:81)
    at org.jboss.weld.injection.producer.BasicInjectionTarget.postConstruct(BasicInjectionTarget.java:114)
    at org.jboss.weld.injection.producer.BeanInjectionTarget.postConstruct(BeanInjectionTarget.java:70)
    at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:153)
    at com.vaadin.cdi.internal.UIBeanStore.getBeanInstance(UIBeanStore.java:53)
    at com.vaadin.cdi.internal.UIScopedContext.get(UIScopedContext.java:105)
    at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:740)
    at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:760)
    at org.jboss.weld.util.ForwardingBeanManager.getReference(ForwardingBeanManager.java:61)
    at org.jboss.weld.bean.builtin.BeanManagerProxy.getReference(BeanManagerProxy.java:78)
    at com.vaadin.cdi.CDIViewProvider.getView(CDIViewProvider.java:213)
    at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:513)
    at com.inteacc.util.MenuLeave$1.itemClick(MenuLeave.java:89)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508)
    at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198)
    at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)
    at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:979)
    at com.vaadin.ui.Tree.changeVariables(Tree.java:470)
    at com.vaadin.server.communication.ServerRpcHandler.changeVariables(ServerRpcHandler.java:485)
    at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:301)
    at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:180)
    at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:93)
    at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)
    at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1406)
    at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:305)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.invokeMethods(DefaultLifecycleCallbackInvoker.java:98)
    ... 58 more
Caused by: java.lang.NullPointerException
    at com.my.view.TreeTableView.initComponent(TreeTableView.java:161)
    ... 63 more
Info:   i am here : country: Canada city: Toronto
Info:   i am here : country: Canada city: Ajax
Info:   i am here : country: Canada city: Vaughan
Info:   i am here : country: Canada city: Brampton
Info:   i am here : country: USA city: New York
Info:   i am here : country: South Korea city: trytrh

Whats on line 161?

Caused by: java.lang.NullPointerException
    at com.my.view.TreeTableView.initComponent(TreeTableView.java:161)

Hi, It is

        ttable.setContainerDataSource(container);

It seems you haven’t created the Table component at that point (since ttable is null). Please fix that, and try again.

Thanks, I made a silly mistake, didn`t initiate creating TreeTable. Now there is no exception, treetable displayed but plain table with nodes though there are number of addresses in the database for differet countries existing. Please take a look at the screen-shot attached.

Thanks fot any further help.
17714.png

I don’t know what to tell you; obviously there is some issue with how you construct the tree. To create a hierarchy, you first need to add the parent, then the child, then connect the child to the parent through their ItemIds.

You can start debugging with checking if setParent returns ‘true’ or not. If it returns ‘false’, then the operation didn’t work, either because the parent or child wasn’t in the container, or because you are trying to create a cyclical tree.

Oh, I just realized after looking at your code again:

container.setParent(a,c); won’t work, because you aren’t using a or c as ItemIds (you call addItem(), that generates an itemId; call addItem(c) to use c as itemId).

Thank you Thomas. Now it worked.

Need to polish it further… the parent row doesn`t have child item info (attached picture.)

here is latest code:

        for (Country c : ctry) {
            Object cItem = container.addItem();
            container.getContainerProperty(cItem, "countryName").setValue(c.getCountryname());
            for (Address a : addr) {
                if (c.getCountryname().equalsIgnoreCase(a.getCountry().getCountryname())) {
                    Object aItem = container.addItem();
                    container.getContainerProperty(aItem, "city").setValue(a.getCity());
                    container.getContainerProperty(aItem, "street").setValue(a.getStreet());

                    container.addItem(aItem);
                    container.setParent(aItem, cItem);

                }
            }
        }

17719.png