com.vaadin.ui.CheckBox already has a parent

Hi Vaadin Experts,

Please help me out with the following error.It was like a hell for me to track this.

I has a table with checkbox in it.While i am trying to get the componets into the table i am getting the following error.java.lang.IllegalStateException: com.vaadin.ui.CheckBox already has a parent.

[b]
[u]

[/u]myPOJO:
[/b]
public class EcoWeed implements Serializable {
private long ecoWeedId;
private String season=null;
private String field=null;
private Date date;
private String crop=null;
private String weed=null;
private String type=null;
private String stage=null;
private String occurance=null;
private String rootType=null;
private String behaviour=null;
private String severity=null;
private String weedManagement=null;
private String mechanism=null;
private boolean delete=true;
private CheckBox check=new CheckBox();
public long getEcoWeedId() {
return ecoWeedId;
}
public void setEcoWeedId(long ecoWeedId) {
this.ecoWeedId = ecoWeedId;
}
public String getSeason() {
return season;
}
public void setSeason(String season) {
this.season = season;
}
public String getField() {
return field;
}
public void setField(String field) {
this.field = field;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getCrop() {
return crop;
}
public void setCrop(String crop) {
this.crop = crop;
}
public String getWeed() {
return weed;
}
public void setWeed(String weed) {
this.weed = weed;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getStage() {
return stage;
}
public void setStage(String stage) {
this.stage = stage;
}
public String getOccurance() {
return occurance;
}
public void setOccurance(String occurance) {
this.occurance = occurance;
}
public String getRootType() {
return rootType;
}
public void setRootType(String rootType) {
this.rootType = rootType;
}
public String getBehaviour() {
return behaviour;
}
public void setBehaviour(String behaviour) {
this.behaviour = behaviour;
}
public String getSeverity() {
return severity;
}
public void setSeverity(String severity) {
this.severity = severity;
}
public String getWeedManagement() {
return weedManagement;
}
public void setWeedManagement(String weedManagement) {
this.weedManagement = weedManagement;
}
public String getMechanism() {
return mechanism;
}
public void setMechanism(String mechanism) {
this.mechanism = mechanism;
}
public boolean isDelete() {
return delete;
}
public void setDelete(boolean delete) {
this.delete = delete;
}
public CheckBox getCheck() {
return check;
}
public void setCheck(CheckBox check) {
this.check = check;
}

}

[b]
[u]

[/u]mycontainer
[/b]

public class EcoWeedContainer extends BeanItemContainer implements Serializable {

public static final Object[] NATURAL_COL_ORDER = new Object[]

{“date”,“season”,“field”,“crop”,“weed”,“type”,“stage”,“occurance”,
“rootType”,“behaviour”,“severity”,“weedManagement”,“mechanism”,“check”};

public static final String[] COL_HEADERS_ENGLISH = new String[]

{“Date”,“Season”,“Field”,“Crop”,“Weed”,“Type”,“Stage”,“Occurance”,
“RootType”,“Behaviour”,“Severity”,“WeedManagement”,“Mechanism”,“Check”};

public EcoWeedContainer() throws InstantiationException,IllegalAccessException {
	super(EcoWeed.class);
}

public static EcoWeedContainer createWithTestData() {
	EcoWeedContainer ecoWeedContainer = null;
	try {
		ecoWeedContainer = new EcoWeedContainer();
		Session session = HibernateUtil.currentSession();
		Transaction txn = session.beginTransaction();
		 Query query = session.createQuery(" from EcoWeed");
		 
		 for(Iterator<EcoWeed> list = query.iterate();list.hasNext();){
		  EcoWeed dbEcoWeed = (EcoWeed)list.next();
		   EcoWeed ecoWeed = new EcoWeed();
		    ecoWeed.setEcoWeedId(dbEcoWeed.getEcoWeedId());
		    ecoWeed.setDate(dbEcoWeed.getDate());
		    ecoWeed.setSeason(dbEcoWeed.getSeason());
		    ecoWeed.setField(dbEcoWeed.getField());
		    ecoWeed.setCrop(dbEcoWeed.getCrop());
		    ecoWeed.setWeed(dbEcoWeed.getWeed());
		    ecoWeed.setType(dbEcoWeed.getType());
		    ecoWeed.setStage(dbEcoWeed.getStage());
		    ecoWeed.setOccurance(dbEcoWeed.getOccurance());
		    ecoWeed.setRootType(dbEcoWeed.getRootType());
		    ecoWeed.setBehaviour(dbEcoWeed.getBehaviour());
		    ecoWeed.setSeverity(dbEcoWeed.getSeverity());
		    ecoWeed.setWeedManagement(dbEcoWeed.getWeedManagement());
		    ecoWeed.setMechanism(dbEcoWeed.getMechanism());
		   
			ecoWeedContainer.addItem(ecoWeed);	
			
		 }
		 txn.commit();
	     HibernateUtil.closeSession();
	} catch (InstantiationException e) {
		e.printStackTrace();
	} catch (IllegalAccessException e) {
		e.printStackTrace();
	}
	return ecoWeedContainer;
}

}

[b]
[u]

[/u]MY Table
[/b]

public class EcoWeedList extends Table {
FarmerInfo farmerInfo=null;
public EcoWeedList(FarmerInfo farmerInfo){
this.farmerInfo=farmerInfo;

	try{
				
		
		
		
		setSizeFull();
		setContainerDataSource(farmerInfo.getEcoWeedSource());
		setVisibleColumns(EcoWeedContainer.NATURAL_COL_ORDER);
		
		 
		setColumnReorderingAllowed(true);
		setColumnCollapsingAllowed(true);
		setSelectable(true);
		setImmediate(true);
		setVisible(true);
		setSelectable(true);
		setImmediate(true);
		setVisible(true);
		setColumnCollapsingAllowed(true);
		setColumnReorderingAllowed(true);
		setHeight("100%");
       
		setPageLength(6);

		addListener((ValueChangeListener)farmerInfo );

		setSelectable(true);
		setImmediate(true);
		
		setNullSelectionAllowed(false);
		
		setColumnHeaders(EcoWeedContainer.COL_HEADERS_ENGLISH);
		setColumnIcon("check", new ThemeResource("icons/32/checkbox-uncheck.png")); 
        setSelectable(true);
        setImmediate(true);
        setVisible(true);
        addListener((HeaderClickListener)farmerInfo); 
		}
		catch(Exception e){		
				e.printStackTrace();
		}
}

}


StackTrace

SEVERE: Terminal error:
java.lang.IllegalStateException: com.vaadin.ui.CheckBox already has a parent.
at com.vaadin.ui.AbstractComponent.setParent(AbstractComponent.java:555)
at com.vaadin.ui.Table.refreshRenderedCells(Table.java:1589)
at com.vaadin.ui.Table.getVisibleCells(Table.java:2703)
at com.vaadin.ui.Table.paintContent(Table.java:2314)
at com.vaadin.ui.AbstractComponent.paint(AbstractComponent.java:754)
at com.vaadin.ui.AbstractOrderedLayout.paintContent(AbstractOrderedLayout.java:171)
at com.vaadin.ui.AbstractComponent.paint(AbstractComponent.java:754)
at com.vaadin.ui.TabSheet.paintContent(TabSheet.java:404)
at com.vaadin.ui.AbstractComponent.paint(AbstractComponent.java:754)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.writeUidlResponce(AbstractCommunicationManager.java:952)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.paintAfterVariableChanges(AbstractCommunicationManager.java:839)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:765)
at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:296)
at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:483)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)

The problem is caused by the way table is rendered. If you have a table in editable mode, only the components for the visible area are created dynamically and when you scroll back and forth (outside the row cache window), they are recreated. For columns with components, the components do not have to be created dynamically, as they come from the container, but their the table must be set as their parent. For some reason Table re-sets the parent to itself. This could be a bug, but it sounds strange as then it should happen always when you have components in a table.

Does the error occur immediately when the table is shown or after scrolling back-and-forth?

There is also a problem that such container must not be bound to two tables simultaneously.

Hi Marko,
Thanks for your earlier response.


“Does the error occur immediately when the table is shown or after scrolling back-and-forth?”

It is not even displaying the table. I am getting the Internal error straight way as soon as i click that tab.

Nothing particular that could cause the problem catches my eye. Using the “addItem()” looks suspicious, you probably should use addBean() there. Having components in a BeanItemContainer should work, as it
does here
.

There’s probably something that causes the container to be used twice. Make sure that the container is not bound to anything else simultaneously. It could also be something trivial, such as server serializing the application - always use ?restartApplication during development. It’s anyhow a bit dangerous to have components in a BeanItemContainer, for the earlier mentioned reason.