Table already has a parent.

Hi

I have class A which extends an Abstract class B and that abstract class B extends Table.

When I run on my local machine, I can nicely view the table, when I deploy it to the development environment I get the error message saying class A already has a parent.

Any idea what is causing this?

Hi Clare,

normally there should no difference if your class extends another class or not. This message says your component instance has been already has been added to another component.

https://vaadin.com/api/com/vaadin/ui/Component.html#setParent(com.vaadin.ui.HasComponents)

But actually on your local machine you should get this error too. Did you check your log files?

Yes, I have no errors, in my local machine. I set the setParent(null) in both classes but still it gives me the error in development environment

I have added this table component to a tableLayout (horizontallayout) as shown below.

this should work isnt it?

if (documents.size() > 0) {
tableLayout.setParent(null);
tableLayout.addComponent(new IntelsTable(documents, workflowViewResource));
}
else {
tableLayout.setParent(null);
tableLayout.addComponent(ViewUtils.buildLabel(msg));
}

    if (viewAll) {
        tableLayout.setParent(null);
        tableLayout.addComponent(ViewUtils.buildViewAllButton(getAllDocsClickListener()));
    }

Hmm, the code actually throwing this IllegalStateException (this is the exception you get, isn’t it?) is pretty much straight forward. Look at com.vaadin.ui.AbstractComponent.setParent(HasComponents).
Did you check the stack trace? Maybe your component is being added to another component at some other point.

yes it is an illegal state exception.

Yes i did.

at com.vaadin.ui.AbstractComponent.setParent(AbstractComponent.java:465)
at com.vaadin.ui.Table.registerComponent(Table.java:2376)
at com.vaadin.ui.Table.parseItemIdToCells(Table.java:2363)
at com.vaadin.ui.Table.getVisibleCellsNoCache(Table.java:2173)
at com.vaadin.ui.Table.refreshRenderedCells(Table.java:1694)
at com.vaadin.ui.Table.attach(Table.java:4171)
at com.vaadin.server.AbstractClientConnector.attach(AbstractClientConnector.java:583)
at com.vaadin.ui.AbstractComponent.attach(AbstractComponent.java:572)
at com.vaadin.server.AbstractClientConnector.attach(AbstractClientConnector.java:583)
at com.vaadin.ui.AbstractComponent.attach(AbstractComponent.java:572)
at com.vaadin.server.AbstractClientConnector.attach(AbstractClientConnector.java:583)
at com.vaadin.ui.AbstractComponent.attach(AbstractComponent.java:572)
at com.vaadin.server.AbstractClientConnector.attach(AbstractClientConnector.java:583)
at com.vaadin.ui.AbstractComponent.attach(AbstractComponent.java:572)
at com.vaadin.server.AbstractClientConnector.attach(AbstractClientConnector.java:583)
at com.vaadin.ui.AbstractComponent.attach(AbstractComponent.java:572)
at com.vaadin.ui.AbstractComponent.setParent(AbstractComponent.java:479)
at com.vaadin.ui.CustomComponent.setCompositionRoot(CustomComponent.java:121)
at uk.co.sovini.flowmobile.views.LogoViewTemplate.enter(LogoViewTemplate.java:26)
at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:571)
at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:526)

I am only adding this tablecomponent only once. that is why i dont get the error in my local i think

        tableLayout.addComponent(new IntelsTable(documents, workflowViewResource));

this is the only place.

I still couldnt resolve the problem? Can you please help me out?

What is a idea to manipulate with setParent?

Sorry I didnt undertstand your comment

I am sorry, I can’t see the actual error.
You are using the navigator. I don’t know exactly what happens but the stored View maybe could do something :slight_smile:

Actually you are creating a new instance when adding the component, so your code seems correct. But does your IntelTable implement View and is being called by your NavigatorProvider? So you are adding the view manually and than the navigator is trying to add the view/table to the configured component. That
may
be the case.

It implements an AbsstractTable which again the AbstractTable extends Table.

I saw one problem though

if (component.getParent() != this) {
component.setParent(this);
}

this is the - IntelsTable

And the component.getParent is a Vertical Layout and this is causing the problem. How can I set the parent in such a way this will result in true and would not go into the setParent method?

Clare, there are many different ways to reparent your component:

Panel.setContent
ComponentContainer.removeComponent/addComponent
and so on.

I am using a Table I have a generated column which in the class that generates the table.

if (component.getParent() != this) {
component.setParent(this);
}

results in illegalstate expection

at com.vaadin.ui.AbstractComponent.setParent(AbstractComponent.java:465)
at com.vaadin.ui.Table.registerComponent(Table.java:2376)
at com.vaadin.ui.Table.parseItemIdToCells(Table.java:2363)
at com.vaadin.ui.Table.getVisibleCellsNoCache(Table.java:2173)
at com.vaadin.ui.Table.refreshRenderedCells(Table.java:1694)
at com.vaadin.ui.Table.attach(Table.java:4171)
at com.vaadin.server.AbstractClientConnector.attach(AbstractClientConnector.java:583)
at com.vaadin.ui.AbstractComponent.attach(AbstractComponent.java:572)
at com.vaadin.server.AbstractClientConnector.attach(AbstractClientConnector.java:583)
at com.vaadin.ui.AbstractComponent.attach(AbstractComponent.java:572)
at com.vaadin.server.AbstractClientConnector.attach(AbstractClientConnector.java:583)
at com.vaadin.ui.AbstractComponent.attach(AbstractComponent.java:572)
at com.vaadin.server.AbstractClientConnector.attach(AbstractClientConnector.java:583)
at com.vaadin.ui.AbstractComponent.attach(AbstractComponent.java:572)
at com.vaadin.server.AbstractClientConnector.attach(AbstractClientConnector.java:583)
at com.vaadin.ui.AbstractComponent.attach(AbstractComponent.java:572)
at com.vaadin.ui.AbstractComponent.setParent(AbstractComponent.java:479)
at com.vaadin.ui.CustomComponent.setCompositionRoot(CustomComponen

Why do you need to call setParent explicitly for the generated column? Relation between generated columns and table is keeped by Vaadin internal.

The thing is I have a generated column in which I decided some color coding, however when I run the application it goes inside the below method and my table is in a vertical Layout and this is the TABLE it self. so it gives me that exception. I want to know how can I prevent from going inside that method?

if (component.getParent() != this) {
component.setParent(this);
}

It would be good if you will show
small isolated
code which reproduce your problem. Is it possible? Can you create new small project where we can see your problem?

Remove the newLabel member and create absolutly new Label objects inside generateCell

Hi

I did as you told me. It works on my local but on the development environement it gives me this error.

Any idea?

Caused by: java.lang.IllegalStateException: uk.co.sovini.flowmobile.views.components.tables.IntelsTable already has a parent.
at com.vaadin.ui.AbstractComponent.setParent(AbstractComponent.java:465)
at com.vaadin.ui.Table.registerComponent(Table.java:2376)
at com.vaadin.ui.Table.parseItemIdToCells(Table.java:2363)
at com.vaadin.ui.Table.getVisibleCellsNoCache(Table.java:2173)
at com.vaadin.ui.Table.refreshRenderedCells(Table.java:1694)
at com.vaadin.ui.Table.attach(Table.java:4171)
at com.vaadin.server.AbstractClientConnector.attach(AbstractClientConnector.java:583)
at com.vaadin.ui.AbstractComponent.attach(AbstractComponent.java:572)
at com.vaadin.server.AbstractClientConnector.attach(AbstractClientConnector.java:583)
at com.vaadin.ui.AbstractComponent.attach(AbstractComponent.java:572)
at com.vaadin.server.AbstractClientConnector.attach(AbstractClientConnector.java:583)
at com.vaadin.ui.AbstractComponent.attach(AbstractComponent.java:572)
at com.vaadin.server.AbstractClientConnector.attach(AbstractClientConnector.java:583)
at com.vaadin.ui.AbstractComponent.attach(AbstractComponent.java:572)
at com.vaadin.server.AbstractClientConnector.attach(AbstractClientConnector.java:583)
at com.vaadin.ui.AbstractComponent.attach(AbstractComponent.java:572)
at com.vaadin.ui.AbstractComponent.setParent(AbstractComponent.java:479)
at com.vaadin.ui.CustomComponent.setCompositionRoot(CustomComponent.java:121)
at uk.co.sovini.flowmobile.views.LogoViewTemplate.enter(LogoViewTemplate.java:26)
at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:571)
at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:526)

Are you sure that you deploy the correct version of your war?

Yes its only one file that I committed to the repository and then maven generates the war file.

Please, show me the corrected version of IntelsTable. You can use {…} to put code.