Autoanswer:

  I can determine if the Widget is an instance of whatever class and
then cast it to get the appropriate object:

Widget fieldItem = hPanel.getWidget(i);
if (fieldItem instanceof TextBox) { // TextBox ?
        TextBox dataItem = (TextBox) fieldItem;
        dataSet[i][1] = dataItem.getText();
} else if (fieldItem instanceof CheckBox) { // CheckBox ?
        CheckBox dataItem = (CheckBox) fieldItem;
        if (dataItem.getValue()) { dataSet[i][1] = "TRUE"; }
        else { dataSet[i][1] = "FALSE"; }
} else if (fieldItem instanceof TextArea) { // TextArea ?
        TextArea dataItem = (TextArea) fieldItem;
        dataSet[i][1] = dataItem.getText();
}

Miguel

On 10 feb, 16:53, mrubioroy <[email protected]> wrote:
> Hi all,
>   I'm dynamically adding different widgets (TextBox, CheckBox or
> TextArea) to a Panel, depending on the columns found in an SQL table.
> Once the different fields are filled up by the user and the "Save"
> button is clicked, the code must collect all the introduced data and
> send it to server side.
>   The problem I have is: How do I access data on every widget without
> knowing what class is each one? That is, I can have access to any
> widget in the Panel, using the getWidget method:
>      myPanel.getWidget(i)
>   But how do I access data? I've tried something like
>      TextBox myWidget;
>      myWidget = (TextBox) myPanel.getWidget(i);
>      String data = myWidget.getText();
>   But this generates an exception if the Widget is of type CheckBox,
> because it cannot be cast to TextBox class.
>   If I could determine the class of myPanel.getWidget(i), then I would
> use some if's to cast that to whatever class it's needed.
>
> Thanks
>
> Miguel

-- 
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