already ha a parent

Hello

i need your help :slight_smile:

I am getting this exception: Caused by: java.lang.IllegalStateException: com.vaadin.ui.CheckBox already has a parent

can somebody help me? i don´t know what to do

my plan:

i´ve got a composite class with 2 tables

then i´ve got also some objects with 2 containers in it.

for each object i´ve got a button.
if i press button a then it should open the composite and show me the items in container a in table a an items in container b in table b. these items are checkboxes. if i check or uncheck a checkbox, i want it to store in the item. an when i press button a the next time, the checkbox should still be check/uncheckd.

hope anybode understands my problem explained in my bad english :slight_smile:
12575.png

You are most likely adding the same component (CheckBox) to multiple ComponentContainers. I couldn’t get a clear picture of what you are trying to achieve, but you should probably create another object for the 2nd ComponentContainer. That, or you must remove the CheckBox from its prior parent before adding it to a new one.

If you can’t solve your problem, you might want to help us help you by sharing some code.

hmm i´ve found the failure source.

Window win = event.getComponent().getWindow();
win.getParent().removeWindow(win);

is there an other way to close a subwindo by pressing a button??? maybe without getParent()

The Window class does have a close()-method, but for some reason it is protected. You can of course override the method and make it public, but in the end the method does the exact same thing you are already doing.

hmm ok this is not getting us anywhere…

here some code:

final Window window= new Window();
window.setModal(true);

HorizontalLayout horLayout = new HorizontalLayout();
btn_subOk = new Button("ok");
horLayout.addComponent(btn_subOk);

VerticalLayout verLayout = new VerticalLayout();
final TextField txtField = new TextField();
verLayout.addComponent(txtField);
verLayout.addComponent(horLayout);

window.addComponent(verLayout);
btn_add.getApplication().getMainWindow().addWindow(window);
window.setWidth("200px");

btn_subOk.addListener(new Button.ClickListener(){
		public void buttonClick(ClickEvent event) {
			if (event.getButton() == btn_subOk) {
				if (txtField.getValue() == "") { 
					getWindow().showNotification("please enter a correct item name");
				} else {
					createObject(.......);
                                 
                               	}
			}
		});
			
		Window win = event.getComponent().getWindow();
		win.getParent().removeWindow(win);
}

i hope this helps a littebit to understand my problem :slight_smile:

My plan:
i´ve got some object with a container. in this container there are objects with the attribute “name”. this name i want to show in a table. under this table there is a button to add new strings/objects. you press this button and a new subwindow (“window”) appears. in this subwindow you can enter a new name for the object (txt_field). with the button btn_subOk you confirm the input an the ne object is beeing created an the name is shown in the table.

the first time i do this it works fine but the second time i push the btn_subOk i get the exception “Caused by: java.lang.IllegalStateException: com.vaadin.ui.Button already has a parent.”

did my problem become clear for you???

What row is throwing the exception?

SCHWERWIEGEND: Terminal error:
com.vaadin.event.ListenerMethod$MethodException: Invocation of method buttonClick in com.example.composits.myClass$5$1 failed.
	at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:530)
	at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:164)
	at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1219)
	at com.vaadin.ui.Button.fireClick(Button.java:567)
	at com.vaadin.ui.Button.changeVariables(Button.java:223)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.changeVariables(AbstractCommunicationManager.java:1460)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(AbstractCommunicationManager.java:1404)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1329)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:761)
	at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:318)
	at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:501)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: com.vaadin.ui.Button already has a parent.
	at com.vaadin.ui.AbstractComponent.setParent(AbstractComponent.java:546)
	at com.vaadin.ui.Table.registerComponent(Table.java:1985)
	at com.vaadin.ui.Table.getVisibleCellsNoCache(Table.java:1943)
	at com.vaadin.ui.Table.refreshRenderedCells(Table.java:1542)
	at com.vaadin.ui.Table.refreshRowCache(Table.java:2255)
	at com.vaadin.ui.Table.containerItemSetChange(Table.java:3957)
	at com.vaadin.data.util.AbstractContainer.fireItemSetChange(AbstractContainer.java:200)
	at com.vaadin.data.util.AbstractContainer.fireItemSetChange(AbstractContainer.java:186)
	at com.vaadin.data.util.AbstractInMemoryContainer.fireItemAdded(AbstractInMemoryContainer.java:815)
	at com.vaadin.data.util.AbstractInMemoryContainer.internalAddItemAtEnd(AbstractInMemoryContainer.java:704)
	at com.vaadin.data.util.AbstractBeanContainer.addItem(AbstractBeanContainer.java:494)
	at com.vaadin.data.util.AbstractBeanContainer.addBean(AbstractBeanContainer.java:559)
	at com.vaadin.data.util.BeanItemContainer.addItem(BeanItemContainer.java:226)
	at com.example.composits.myClass$5$1.buttonClick(myClass.java:241)      <--------------------------------------------------
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510)
	... 27 more

its the line whrer i add the new item to the container which is displayed in the table…

container.addItem(item);

OK, now I think I’ve got it. You have a container that includes some checkboxes, and are trying to use that same container in two different tables?

I think this is a bug in Vaadin: i checked the code, and the table doesn’t unregister components from whatever they were attached to before: if (component.getParent() != this) { component.setParent(this); }

I am going to open a ticket for this. Unfortunately I cant really give a workaround either, other than iterating through the container and calling Component.setParent(null) on everything. Not sure if that will even work…

hmmm noyes^^ you didn´t get my idea completely but the checkbox problem i´ve sold with .setParent(null) when i am closing the subwindow

but now nearly the same exception is shown when i click the button. and when i setParent(null) at the button it doesn´t work :slight_smile:

I’m sorry, but you need to provide more info. Without knowing how your UI is implemented, it is very difficult to give any advice.

Your root problem is that you are attaching one component to several ComponentContainers, which is not a well supported operation in Vaadin. A component can only be attached to one ComponentContainer (e.g. Layout or a Table) at a time; it needs to be de-attached from the current container before it can be attached to another. Without knowing more about your application, I can’t say how you can fix this or how you could refactor your code to avoid this.

arghh i forgot to set the parent of the tables to null when i close the window :slight_smile:

now it works fine.

thank you for your help