Hello there,

I'm guessing this is a simple problem, but I can't solve it for days
and I don't know what else to do.

i'm creating a new widget. I'm using the UiBinder with a HTMLPanel,
and in this panel I've created a table. This table has around 50 rows
and 4 columns. I need to have access to each cell to be able to set
its content.

So first I've tried with a simple approach: each cell contains a <span
id="xxx"></span>. On the Java side, I initialize the widget with
initWidget(uiBinder.createAndBindUi(this)); and then set the content
of each span with

RootPanel.get("xxx").add(new Label("xxx"));

The problem was that RootPanel.get("xxx") will always return null. I
was thinking that this is because the widget hasn't yet been added to
its parent component (at that point), so the xxx field hasn't been
attached to the DOM tree.

I've tried a different approach. First I've added the widget, and then
I called something like an initInternalComponents() method, which did
the RootPanel.get("xxx") thing. In this case, I got an exception "A
widget that has an existing parent widget may not be added to the
detach list"

After several hours of trying to fix this, I gave up and tried another
approach.

I replaced all the <span> tags with <g:Label ui:field="xxx"/>. On the
Java side, I declared all 200+ components as a @UiField Label xxx.
This did work.

The problem now is how to access each field. Let's say I want to set
the text of the cell in row 35, column 2. In that case, I'd have a
label with the name field35by2 declared as an @UiField. What I was
thinking of doing is using reflection:

getClass().getField("field"+row+"by"+column).get(this)

This would actually work in a normal Java application, but GWT doesn't
support reflection, so now I'm back to where I've started 2 days ago.

So can anyone help me how to solve this problem? I've tried a table
component but it wasn't what I wanted, it restricted me too much in
accessing a specific cell, or adding random components to different
cells (in the end, I'd also have TextFields, Buttons, ListBoxes in
this tables).

An ideal solution would be to have
Table table = new Table();
for (int row=0; row<50; row++) {
  table.newRow();
  for (int col=0; col<50; col++) {
      Cell cell = table.newCell();
      cell.add( new Label("xxx" ) );
  }
}

and after that, I'd just do table.getCell(35, 2).getWidget() to obtain
the Label or whatever.

How to do this?

Thanks in advance for any help!
Csaba

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

Reply via email to