PDA

View Full Version : Help With Example -Method must be called before the component is rendered



Manuel Elaraj
5 Jun 2008, 12:06 PM
Here is my example. When run i get the exception below. Useing GWT 1.5rc1 with extGWT 1.0Rc4



java.lang.AssertionError: Method must be called before the component is rendered
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:443)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:235)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
at com.extjs.gxt.ui.client.util.WidgetHelper.doAttach(WidgetHelper.java:19)
at com.extjs.gxt.ui.client.widget.Container.doLayout(Container.java:241)
at com.extjs.gxt.ui.client.widget.Container.layout(Container.java:302)
at com.extjs.gxt.ui.client.widget.LayoutContainer.layout(LayoutContainer.java:234)
at com.extjs.gxt.ui.client.widget.Container.onAttach(Container.java:309)
at com.extjs.gxt.ui.client.widget.Viewport.onAttach(Viewport.java:73)
at com.google.gwt.user.client.ui.Widget.setParent(Widget.java:231)




Please see my code below:



public class Gwt_test extends LayoutContainer implements EntryPoint
{

public void onModuleLoad()
{
Viewport v = new Viewport();
v.setLayout(new FillLayout(8));
v.add(this);
RootPanel.get().add(v);
}

@Override
protected void onRender(Element parent, int pos)
{
super.onRender(parent, pos);

setLayout(new FlowLayout(10));

final NumberFormat currency = NumberFormat.getCurrencyFormat();
final NumberFormat number = NumberFormat.getFormat("0.00");

List<TableColumn> columns = new ArrayList<TableColumn>();

TableColumn col = new TableColumn("Company", 180);
col.setMinWidth(75);
col.setMaxWidth(300);
columns.add(col);

col = new TableColumn("Symbol", 75);
columns.add(col);

col = new TableColumn("Last", 75);
col.setMaxWidth(100);
col.setAlignment(HorizontalAlignment.RIGHT);
col.setRenderer(new NumberCellRenderer(currency));
columns.add(col);

col = new TableColumn("Change", 75);
col.setAlignment(HorizontalAlignment.RIGHT);
col.setRenderer(new CellRenderer()
{
public String render(String property, Object value)
{
double val = (Double) value;
String style = val < 0 ? "red" : "green";
return "<span style='color:" + style + "'>" + number.format(val) + "</span>";
}
});
columns.add(col);

col = new TableColumn("Last Updated", 100);
col.setAlignment(HorizontalAlignment.RIGHT);
col.setRenderer(new DateTimeCellRenderer("MM/d/y"));
columns.add(col);

TableColumnModel cm = new TableColumnModel(columns);

Table tbl = new Table(cm);
tbl.setSelectionModel(new RowSelectionModel(SelectionMode.MULTI));
tbl.setHorizontalScroll(true);


for (int i = 0; i < 50; i++)
{

Object[] values = new Object[5];
values[0] = "Manuel Elaraj";
values[1] = "ME";
values[2] = "10";
values[3] = "+2";
values[4] = "12";

TableItem item = new TableItem(values);
tbl.add(item);
}

ContentPanel panel = new ContentPanel();
panel.setCollapsible(true);
panel.setFrame(true);
panel.setAnimCollapse(false);
panel.setButtonAlign(HorizontalAlignment.CENTER);
panel.setIconStyle("icon-table");
panel.setHeading("Table Demo");
panel.setLayout(new FitLayout());
panel.add(tbl);
panel.setSize(575, 350);

// built in support for top component
ToolBar toolBar = new ToolBar();
toolBar.add(new TextToolItem("Add", "icon-add"));
toolBar.add(new SeparatorToolItem());
toolBar.add(new TextToolItem("Remove", "icon-delete"));
toolBar.add(new SeparatorToolItem());
toolBar.add(new TextToolItem("Configure", "icon-plugin"));
panel.setTopComponent(toolBar);

// add buttons
panel.addButton(new Button("Save"));
panel.addButton(new Button("Cancel"));

add(panel);
}

}

Thank you very much,
Manuel Elaraj

bjwaski
5 Jun 2008, 6:49 PM
I'm seeing basically the same error when trying to add buttons to a FormPanel. I moved adding the buttons out of the onRender method and into my component's constructor, and now I don't get the error, but the buttons don't show up. The only real difference between my code and the GXT Explorer's FormPanel example is that I'm adding a FormPanel to a ContentPanel, rather than a tabbed display.

Manuel Elaraj
6 Jun 2008, 3:40 AM
This problem is resolved it was a bug in the build that i had from two days ago. Download the latest build and you are good to go. Just re-download from the same location.

21 May 2009, 3:56 AM
Hi

I am havinng a same kind of problem. I am using the latest bundle of GXT i.e.gxt-2.0-m2, but still i am having exception like

[ERROR] Uncaught exception escaped
java.lang.AssertionError: Method must be called after the component is rendered
at com.extjs.gxt.ui.client.widget.Component.assertAfterRender(Component.java:1286)
at com.extjs.gxt.ui.client.widget.Component.el(Component.java:406)
at com.duke.irb.client.DashBoard.attachListener(DashBoard.java:57)
at com.duke.irb.client.LogIn.CreateLogInForm$1$1.onSuccess(CreateLogInForm.java:96)
at com.duke.irb.client.LogIn.CreateLogInForm$1$1.onSuccess(CreateLogInForm.java:1)
at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:215)
at com.google.gwt.http.client.Request.fireOnResponseReceivedImpl(Request.java:264)
at com.google.gwt.http.client.Request.fireOnResponseReceivedAndCatch(Request.java:236)
at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:227)
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.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.ie.IDispatchImpl.callMethod(IDispatchImpl.java:126)
at com.google.gwt.dev.shell.ie.IDispatchProxy.invoke(IDispatchProxy.java:155)
at com.google.gwt.dev.shell.ie.IDispatchImpl.Invoke(IDispatchImpl.java:294)
at com.google.gwt.dev.shell.ie.IDispatchImpl.method6(IDispatchImpl.java:194)
at org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:117)
at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1925)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2966)
at com.google.gwt.dev.SwtHostedModeBase.processEvents(SwtHostedModeBase.java:235)
at com.google.gwt.dev.HostedModeBase.pumpEventLoop(HostedModeBase.java:558)
at com.google.gwt.dev.HostedModeBase.run(HostedModeBase.java:405)
at com.google.gwt.dev.HostedMode.main(HostedMode.java:232)

I am trying to add event listeners to a tree elements. The event Listener will do nothing but will act like as a hyperlink. I have created the tree and now trying to add event Listeners with the child elements.

The code fragement for creating the tree is :

public class DashBoard extends LayoutContainer{
Tree tree = new Tree();
VerticalPanel vp = new VerticalPanel();

protected void onRender(Element target, int index) {
super.onRender(target, index);

tree.getStyle().setLeafIconStyle("icon-info");
TreeBuilder.buildTree(tree, IrbModels.getTreeModel());

vp.setSpacing(10);
vp.add(tree);
setLayout(new FlowLayout());
add(vp);

RootPanel.get().add(vp);
attachListener();
}after that I have tried to add event listeners to the siblings which dont have child nodes and I am having the problem at :

attachListener(){
tree.getItem(2).el().addEventsSunk(Event.MOUSEEVENTS);
}


Can anybody please help me out.

thanks in advance.




Raul
[email protected]

dianbo
17 Jun 2009, 7:04 AM
Maybe there are some error before the window has show, you can comment the code of the content before the window.show() to make sure that where is the problem