0

I am facing some difficulties with GXT SimpleComboBox. Can someone please tell me how to add combo box items from an external *.xml file? Here is more details:

I have this information.ui.xml file as a uibinder. Here, I have added a simple combo box using the following code:

<row:VerticalLayoutContainer borders="true">
    <f:SimpleComboBox ui:field="listBoxField"></f:SimpleComboBox>
</row:VerticalLayoutContainer>

Second, in the code-behind class (in my case, information.java), I have declared the ui field:

@UiField
SimpleComboBox<String> listBoxField;

Then, in the asWidget() method block, I have added some entries manually, as in:

listBoxField.add("A");
listBoxField.add("B");
listBoxField.add("C");
listBoxField.add("D");
listBoxField.add("E");
listBoxField.add("F");
listBoxField.add("G");
listBoxField.add("H");

This is a hard-coded approach. Now I am willing to get rid of the hard-coding part. I want to add the listBoxField items (A, B, C... H) directly from an external *.xml file. Can anyone help me on how to do that?

Thanks.

1 Answers1

0

There are literally thousands of howto's (at SO and elsewhere) describing the steps necessary to read data from XML files. Google is your friend here...

I'll answer your question with a question though: Why does it have to be XML files? How about ResourceBundle's or even better, database backed. Using a DB you don't have to redeploy your application every time the XML or bundle changes...

Cheers,

Anders R. Bystrup
  • 15,729
  • 10
  • 59
  • 55
  • I personally an not a fan of xml myself! My own preference is Database backed. But it is a requirement that I must fulfill. That's why I am looking for the howto's... Thanks! – Roohul Poolak Nov 15 '12 at 11:48
  • I was actually kinda hoping that there'd be a direct way to do the trick in GXT. Seems there ain't... :( – Roohul Poolak Nov 15 '12 at 11:49
  • The main reason there isn't is that UiBinder is pretty specifically built to not allow custom element/attribute handlers. Most of the workarounds that were devised and worked nicely with 2.4 and before suddenly stopped working in 2.5.0. The stated design goals are to build up widget, and not a lot else. The comparable class in GWT itself, `ValueListBox` also can't handle this - but, `ListBox` can! Why, you ask? a) specially built workarounds in UiBinder itself, that only work for explicitly supported widgets, and b) ComboBox/SimpleComboBox are generic, so we can't just expect strings. – Colin Alworth Nov 17 '12 at 05:52