View Full Version : java.lang.IllegalStateException: Should only call onDetach when the widget is attache

13 May 2009, 3:11 PM
Hi folks!
This problem (java.lang.IllegalStateException: Should only call onDetach when the widget is attache) has been discussed on Ext-Gwt forum for 1.x version, but this problem still remains on the 2.x M1.

My hierarchy scenario:
RootPanel (body) -> div element (directly on html) -> LayoutContainer (gxt api) (with 3 ContentPanel (gxt api), north, east and west, like a splitter), in the east frame I have a tree menu, when I click it changes the view on the west frame. (Pretty common)
The west frame hierarchy is SimplePanel (gwt api) -> VerticalPanel (gwt api) -> FormPanel (gxt api) -> many widgets (gxt api).

The SimplePanel remains in the west frame, and what only change is the VerticalPanel inside it.

The bug occurs right when click to change the view on the west frame.

simplePanel.setWidget(content); (where content is a VerticalPanel)

I debugged the gxt api and the problem occurs when it try to exceute an onDetach method to the FormPanel widget.

I was a little bored with that error, than try to solve it creating a recursive method to remove all leaf widget before the containers, the code follows:


private static void clear(Widget w) {
if(w != null) {
if(w instanceof Panel) {
Iterator<Widget> it = ((Panel)w).iterator();
while(it.hasNext()) {
Widget wTemp = it.next();
} else {
if(w instanceof ContentPanel) {
Object[] list = ((ContentPanel)w).getItems().toArray();
for(int i=0;list != null && i < list.length;i++) {
} else {
}Result? It worked! :D

Best regards!