How to add an Element object into a Widget.

529 views
Skip to first unread message

Rizen

unread,
May 28, 2010, 7:08:34 AM5/28/10
to Google Web Toolkit
Hello,

For my project, I would like to create a table in HTML by means of the
DOM tree.
For this, I'm just using the functions DOM.createTable(),
DOM.createTBody(), DOM.createTR()...
However the generated table is an Element type.

Except that I'm using the MVP as a pattern for my application. So I
have to init the main Widget with the function initWidget(), which
takes a Widget object as parameter. I was looking for a panel like the
HTMLPanel but no method can change or add an Element into a Widget.

Is there a method that I can use to cast the Element object in Widget
object ?

Here is an example of code :

public class View extends Composite {

public View() {
Element table = DOM.createTable();
Element tbody = DOM.createTBody();
Element tr = DOM.createTR();
Element td = DOM.createTD();

tr.appendChild(td);
tbody.appendChild(tr);
table.appendChild(tbody);

// Need a Widget as a type
initWidget(table);
}
}

Olivier Monaco

unread,
May 28, 2010, 9:49:37 AM5/28/10
to Google Web Toolkit
Replace Composite by Widget and initWidget by setElement...

You can also you GWT tables...

Olivier

kozura

unread,
May 28, 2010, 1:27:43 PM5/28/10
to Google Web Toolkit
Any particular reason not to just use the Grid widget? The overhead
is negligible and the code a lot simpler..

Rizen

unread,
May 28, 2010, 3:13:00 PM5/28/10
to Google Web Toolkit
Thank you very much, I tried to replace Composite by Widget and for
the moment it seems to work.

I can't use the Grid widget cause I need a Dynamic Table.
Moreover I have to reuse an existing CSS file. This one uses few table
elements like thead, tbody, tfoot et others styles name.
So I must create a personalized table in the DOM tree.

I used the function DOM.createTable(). But my table is hugh and it's
very long to coding step by step.
Is the TableElement class better ? Cause I don't know how to create a
tbody element in my HTML page with this.

Thanks a lot.
P.S. : sorry if my english is a little bad, I'm french ^^.
Reply all
Reply to author
Forward
0 new messages