1. #1
    Sencha User
    Join Date
    Oct 2011
    Posts
    20
    Vote Rating
    0
    nstokoe is on a distinguished road

      0  

    Default Unanswered: GXT 3.0 - SimpleComboBox populated with Strings

    Unanswered: GXT 3.0 - SimpleComboBox populated with Strings


    Hello!

    I want to create a SimpleComboBox and populate it with plain old Strings. Is there anyway to do this? There is no SimpleComboBox example in the Ext GWT Explorer. Here is what I tried:

    Code:
      SimpleComboBox<String> priorityCombo = new SimpleComboBox<String>(null);
            priorityCombo.add("Value 1");
            priorityCombo.add("Value 2");
            priorityCombo.add("Value 3");
            priorityCombo.setAllowTextSelection(false);
            priorityCombo.setEditable(false);
            priorityCombo.setEnabled(true);
            priorityCombo.setTriggerAction(TriggerAction.ALL);
    And here is the resulting error:

    Code:
    com.google.gwt.user.client.ui.AttachDetachException: One or more exceptions caught, see full set in UmbrellaException#getCauses
        at com.google.gwt.user.client.ui.AttachDetachException.tryCommand(AttachDetachException.java:87)
        at com.sencha.gxt.widget.core.client.container.Container.doAttachChildren(Container.java:310)
        at com.google.gwt.user.client.ui.Widget.onAttach(Widget.java:345)
        at com.sencha.gxt.widget.core.client.Component.onAttach(Component.java:1263)
        at com.google.gwt.user.client.ui.Widget.setParent(Widget.java:475)
        at com.google.gwt.user.client.ui.Panel.adopt(Panel.java:127)
        at com.google.gwt.user.client.ui.ComplexPanel.add(ComplexPanel.java:97)
        at com.google.gwt.user.client.ui.AbsolutePanel.add(AbsolutePanel.java:97)
        at com.sencha.gxt.cell.core.client.form.ComboBoxCell.expand(ComboBoxCell.java:358)
        at com.sencha.gxt.cell.core.client.form.ComboBoxCell.onResultsLoad(ComboBoxCell.java:949)
        at com.sencha.gxt.cell.core.client.form.ComboBoxCell.doQuery(ComboBoxCell.java:337)
        at com.sencha.gxt.cell.core.client.form.ComboBoxCell.onTriggerClick(ComboBoxCell.java:1034)
        at com.sencha.gxt.cell.core.client.form.TriggerFieldCell.onClick(TriggerFieldCell.java:339)
        at com.sencha.gxt.cell.core.client.form.TriggerFieldCell.onBrowserEvent(TriggerFieldCell.java:241)
        at com.sencha.gxt.cell.core.client.form.ComboBoxCell.onBrowserEvent(ComboBoxCell.java:508)
        at com.sencha.gxt.widget.core.client.cell.CellComponent.onBrowserEvent(CellComponent.java:221)
        at com.sencha.gxt.widget.core.client.form.Field.onBrowserEvent(Field.java:318)
        at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1351)
        at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1307)
        at sun.reflect.GeneratedMethodAccessor35.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
        at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
        at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
        at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
        at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
        at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
        at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
        at sun.reflect.GeneratedMethodAccessor29.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
        at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
        at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
        at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
        at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
        at java.lang.Thread.run(Thread.java:679)
    Caused by: java.lang.NullPointerException: null
        at com.sencha.gxt.cell.core.client.LabelProviderSafeHtmlRenderer.render(LabelProviderSafeHtmlRenderer.java:26)
        at com.google.gwt.cell.client.AbstractSafeHtmlCell.render(AbstractSafeHtmlCell.java:80)
        at com.sencha.gxt.widget.core.client.ListView.bufferRender(ListView.java:807)
        at com.sencha.gxt.widget.core.client.ListView.refresh(ListView.java:672)
        at com.sencha.gxt.widget.core.client.ListView.onAfterFirstAttach(ListView.java:914)
        at com.sencha.gxt.widget.core.client.Component.onAttach(Component.java:1266)
        at com.google.gwt.user.client.ui.AttachDetachException$1.execute(AttachDetachException.java:34)
        at com.google.gwt.user.client.ui.AttachDetachException.tryCommand(AttachDetachException.java:74)
        at com.sencha.gxt.widget.core.client.container.Container.doAttachChildren(Container.java:310)
        at com.google.gwt.user.client.ui.Widget.onAttach(Widget.java:345)
        at com.sencha.gxt.widget.core.client.Component.onAttach(Component.java:1263)
        at com.google.gwt.user.client.ui.Widget.setParent(Widget.java:475)
        at com.google.gwt.user.client.ui.Panel.adopt(Panel.java:127)
        at com.google.gwt.user.client.ui.ComplexPanel.add(ComplexPanel.java:97)
        at com.google.gwt.user.client.ui.AbsolutePanel.add(AbsolutePanel.java:97)
        at com.sencha.gxt.cell.core.client.form.ComboBoxCell.expand(ComboBoxCell.java:358)
        at com.sencha.gxt.cell.core.client.form.ComboBoxCell.onResultsLoad(ComboBoxCell.java:949)
        at com.sencha.gxt.cell.core.client.form.ComboBoxCell.doQuery(ComboBoxCell.java:337)
        at com.sencha.gxt.cell.core.client.form.ComboBoxCell.onTriggerClick(ComboBoxCell.java:1034)
        at com.sencha.gxt.cell.core.client.form.TriggerFieldCell.onClick(TriggerFieldCell.java:339)
        at com.sencha.gxt.cell.core.client.form.TriggerFieldCell.onBrowserEvent(TriggerFieldCell.java:241)
        at com.sencha.gxt.cell.core.client.form.ComboBoxCell.onBrowserEvent(ComboBoxCell.java:508)
        at com.sencha.gxt.widget.core.client.cell.CellComponent.onBrowserEvent(CellComponent.java:221)
        at com.sencha.gxt.widget.core.client.form.Field.onBrowserEvent(Field.java:318)
        at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1351)
        at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1307)
        at sun.reflect.GeneratedMethodAccessor35.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
        at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
        at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
        at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
        at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
        at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
        at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
        at sun.reflect.GeneratedMethodAccessor29.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
        at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
        at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
        at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
        at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
        at java.lang.Thread.run(Thread.java:679)
    I know this error is the result of passing null instead of a valid LabelProvider in the constructor but it seems to me that a SimpleComboBox should support simple data types. Am I incorrect in this assumption? I wanted to use the GXT widget so that it would visually match the rest of my widgets but I guess my best alternative is to just use a GWT ListBox.

  2. #2
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,734
    Vote Rating
    90
    Answers
    109
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    Did you try using a LabelProvider instead of leaving it null? Java generics don't allow for runtime introspection, so without checking the type of every object that comes into the combo and picking a labelprovider for it, it would be difficult to define a 'default'.

    That said, we could set a default with a StringLabelProvider<T>, and as a simple workaround you could use this in the constructor instead of null. It is a reasonable default, and we will consider it for the next release - but it won't do good on localizing numbers, formatting dates, and RequestFactory proxies are stuck with their standard Object.toString() implementation.

  3. #3
    Sencha User
    Join Date
    Oct 2011
    Posts
    20
    Vote Rating
    0
    nstokoe is on a distinguished road

      0  

    Default


    Thank you! You can mark this answered.

    Changing:

    Code:
    SimpleComboBox<String> priorityCombo = new SimpleComboBox<String>(null);
    to

    Code:
    SimpleComboBox<String> priorityCombo = new SimpleComboBox<String>(new StringLabelProvider<String>());
    did the trick. Now that I see it, it seems painfully obvious. I guess I was just thrown by the fact that there doesn't seem to exist a single example of a working SimpleComboBox in the Explorer or online in general since it was updated to take a LabelProvider. Perhaps you could add a SimpleComboBox example to the Explorer with the regular ComboBox examples.

    Thank you again.

Thread Participants: 1

Tags for this Thread