appendChild Does not work

33 views
Skip to first unread message

Antoxa.c

unread,
Dec 14, 2011, 6:14:05 AM12/14/11
to Google Web Toolkit
I am trying to create simple html table.

Code for table:

public class SimpleTable extends Widget {
private Element tr;

public SimpleTable() {
Element tableElem = DOM.createTable();
Element bodyElem = DOM.createTBody();
DOM.appendChild(tableElem, bodyElem);
setElement(tableElem);

tr = DOM.createTR();
DOM.appendChild(bodyElem, tr);
}

public void addCell(String text) {
Element td = DOM.createTD();
td.setInnerText(text);
DOM.appendChild(tr, td);
}
}

Code for extended class:

public class TimeLine extends SimpleTable {
public TimeLine() {
addCell("text 1");
}
}

But addCell(String text) method does not append new td element to the
table. What is wrong with code?

Ed

unread,
Dec 14, 2011, 10:13:20 AM12/14/11
to google-we...@googlegroups.com
Hard to tell as you code seems ok but you don't give any error details.
Try to debug it and have a look at HorizontalPanel and VerticalPanel as they perform the same kind of actions and that works...
I also do some table building myself like you are doing and works fine..

Antoxa.c

unread,
Dec 14, 2011, 11:01:52 AM12/14/11
to Google Web Toolkit
It does not generate any error. addCell(String text) just do nothing.
Problem appears when extending SimpleTable class. If call addCell
method in SimpleTable constructor all works fine:

public class SimpleTable extends Widget {
private Element tr;
public SimpleTable() {
Element tableElem = DOM.createTable();
Element bodyElem = DOM.createTBody();
DOM.appendChild(tableElem, bodyElem);
setElement(tableElem);
tr = DOM.createTR();
DOM.appendChild(bodyElem, tr);

addCell("text 1"); // difference from previous code! Works!
}

public void addCell(String text) {
Element td = DOM.createTD();
td.setInnerText(text);
DOM.appendChild(tr, td);
}
}

But why it does not work in extended class I do not understand...

Ed Bras

unread,
Dec 14, 2011, 1:48:08 PM12/14/11
to google-we...@googlegroups.com
I wouldn't put it in the constructor anyway but create it all lazily.
I use a SimpleComposite class that extends from Composite and will automatically call the abstract create() method when the creation of the actual widget is required.
- Ed


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


Antoxa.c

unread,
Dec 14, 2011, 2:46:18 PM12/14/11
to Google Web Toolkit
Oh, I am sorry. All really works fine as you told! I made a stupid
mistake in another class)) Ed, thank you for answer!
Reply all
Reply to author
Forward
0 new messages