already ha a parent


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:

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();

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();

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

VerticalLayout verLayout = new VerticalLayout();
final TextField txtField = new TextField();


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 {
		Window win = event.getComponent().getWindow();

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(
	at com.vaadin.event.EventRouter.fireEvent(
	at com.vaadin.ui.AbstractComponent.fireEvent(
	at com.vaadin.ui.Button.fireClick(
	at com.vaadin.ui.Button.changeVariables(
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.changeVariables(
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(
	at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(
	at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(
	at javax.servlet.http.HttpServlet.service(
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(
	at org.apache.catalina.core.StandardWrapperValve.invoke(
	at org.apache.catalina.core.StandardContextValve.invoke(
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(
	at org.apache.catalina.core.StandardHostValve.invoke(
	at org.apache.catalina.valves.ErrorReportValve.invoke(
	at org.apache.catalina.valves.AccessLogValve.invoke(
	at org.apache.catalina.core.StandardEngineValve.invoke(
	at org.apache.catalina.connector.CoyoteAdapter.service(
	at org.apache.coyote.http11.AbstractHttp11Processor.process(
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$ Source)
	at Source)
Caused by: java.lang.IllegalStateException: com.vaadin.ui.Button already has a parent.
	at com.vaadin.ui.AbstractComponent.setParent(
	at com.vaadin.ui.Table.registerComponent(
	at com.vaadin.ui.Table.getVisibleCellsNoCache(
	at com.vaadin.ui.Table.refreshRenderedCells(
	at com.vaadin.ui.Table.refreshRowCache(
	at com.vaadin.ui.Table.containerItemSetChange(
	at com.example.composits.myClass$5$1.buttonClick(      <--------------------------------------------------
	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(
	... 27 more

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


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