1. #1
    Ext User
    Join Date
    Jan 2009
    Posts
    11
    Vote Rating
    0
    explido Software is on a distinguished road

      0  

    Default SimpleComboBox & ModelProcessor Bug?

    The combination of SimpleComboBox & ModelProcessor results in an Exception.
    See the following code


    private final SimpleComboBox<Integer> hourIntervals = new SimpleComboBox<Integer>();
    hourIntervals.setFieldLabel("Intervall");
    hourIntervals.add(Arrays.asList(1, 5, 10, 15, 20, 30, 60));
    hourIntervals.getView().setModelProcessor(new ModelProcessor<SimpleComboValue<Integer>>() {
    public SimpleComboValue<Integer> prepareData(SimpleComboValue<Integer> model) {
    return model.set(model.getValue() + " Min", model);
    }
    });

    results in:

    java.lang.NullPointerException: null
    at com.extjs.gxt.ui.client.util.Util.getJsObject(Util.java:140)
    at com.extjs.gxt.ui.client.util.Util.getJsObjects(Util.java:184)
    at com.extjs.gxt.ui.client.widget.ListView.refresh(ListView.java:398)
    at com.extjs.gxt.ui.client.widget.ListView.setStore(ListView.java:531)
    at com.extjs.gxt.ui.client.widget.form.ComboBox.bindStore(ComboBox.java:1387)
    at com.extjs.gxt.ui.client.widget.form.ComboBox.initList(ComboBox.java:1170)
    at com.extjs.gxt.ui.client.widget.form.ComboBox.onRender(ComboBox.java:1263)
    at com.extjs.gxt.ui.client.widget.Component.render(Component.java:812)
    at com.extjs.gxt.ui.client.widget.Component.render(Component.java:777)
    at com.extjs.gxt.ui.client.widget.layout.FormLayout.renderField(FormLayout.java:317)
    at com.extjs.gxt.ui.client.widget.layout.FormLayout.renderComponent(FormLayout.java:279)
    at com.extjs.gxt.ui.client.widget.Layout.renderAll(Layout.java:228)
    at com.extjs.gxt.ui.client.widget.Layout.onLayout(Layout.java:212)
    at com.extjs.gxt.ui.client.widget.layout.AnchorLayout.onLayout(AnchorLayout.java:73)
    at com.extjs.gxt.ui.client.widget.layout.FormLayout.onLayout(FormLayout.java:260)
    at com.extjs.gxt.ui.client.widget.Layout.layout(Layout.java:91)

    Is there an alternative to format the ComboBox-Values?

    THX

  2. #2
    Ext User
    Join Date
    Jun 2008
    Posts
    365
    Vote Rating
    0
    sdc is on a distinguished road

      0  

    Default

    Try to post a sample code to reproduce the issue, as explained here :

    http://extjs.com/forum/showthread.php?t=40289

  3. #3
    Ext User
    Join Date
    Jan 2009
    Posts
    11
    Vote Rating
    0
    explido Software is on a distinguished road

      0  

    Default ... missing info

    This should comile

    Code:
    public class Test implements EntryPoint {
        
        public void onModuleLoad() {
            Viewport viewport = new Viewport();
            
            setHeading("Test Panel");
            setLayout(new FitLayout());
            
            FormPanel form = new FormPanel();
            
            FormLayout layout = new FormLayout();
            layout.setLabelAlign(LabelAlign.TOP);
            form.setLayout(layout);
    
        private final SimpleComboBox<Integer> hourIntervals = new SimpleComboBox<Integer>();
        hourIntervals.setFieldLabel("Intervall");
        hourIntervals.add(Arrays.asList(1, 5, 10, 15, 20, 30, 60));
        hourIntervals.getView().setModelProcessor(new ModelProcessor<SimpleComboValue<Integer>>() {
            public SimpleComboValue<Integer> prepareData(SimpleComboValue<Integer> model) {
                return model.set(model.getValue() + " Min", model);
            }
        });
    
            form.add(hourIntervals);
    
            viewport.add(form);
            RootPanel.get().add(viewport);
        }
    }
    Prob occurs in hosted & server mode on Windows Vista

    Ext 1.2.2 & GWT 1.5.3

    Exception was allready included above

  4. #4
    Sencha User
    Join Date
    Sep 2007
    Posts
    13,974
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default

    Code:
    hourIntervals.getView().setModelProcessor(new ModelProcessor<SimpleComboValue<Integer>>() {
            public SimpleComboValue<Integer> prepareData(SimpleComboValue<Integer> model) {
                return model.set(model.getValue() + " Min", model);
            }
        });
    What are you trying to do here? Doenst make much sense to me.

  5. #5
    Ext User
    Join Date
    Jun 2008
    Posts
    365
    Vote Rating
    0
    sdc is on a distinguished road

      0  

    Default

    What you want is to display a ComboBox with the following displayed choices in the list :
    1 min
    5 min
    ...
    Is that true ?

  6. #6
    Sencha User
    Join Date
    Sep 2007
    Posts
    13,974
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default

    If that is true than this is the way to go:

    Code:
    hourIntervals.getView().setModelProcessor(new ModelProcessor<SimpleComboValue<Integer>>() {
            public SimpleComboValue<Integer> prepareData(SimpleComboValue<Integer> model) {
                model.set("value", model.getValue() + " Min");
                return model;
            }
        });

  7. #7
    Ext User
    Join Date
    Jan 2009
    Posts
    11
    Vote Rating
    0
    explido Software is on a distinguished road

      0  

    Default solved - thx!

    Thanks a lot! That's exactly what i wanted!

  8. #8
    Ext User
    Join Date
    Jan 2009
    Posts
    11
    Vote Rating
    0
    explido Software is on a distinguished road

      0  

    Default ... enhanced solution

    ... slightly better implemetation conserving the value is to use another newly introduced property let's say "display" and setting this one as displayproperty.

    Code:
            hourIntervals.getView().setModelProcessor(new ModelProcessor<SimpleComboValue<Integer>>() {
                public SimpleComboValue<Integer> prepareData(SimpleComboValue<Integer> model) {
                    model.set("display", model.getValue() + " Min");
                    return model;
                }
            });
            hourIntervals.getPropertyEditor().setDisplayProperty("display");

  9. #9
    Ext User
    Join Date
    Jun 2008
    Posts
    365
    Vote Rating
    0
    sdc is on a distinguished road

      0  

    Default

    Right. By the way, I have experienced some cases where the model was not prepared before the display. To be 100% safe, you can do :
    Code:
            hourIntervals.getView().setModelProcessor(new ModelProcessor<SimpleComboValue<Integer>>() {
                public SimpleComboValue<Integer> prepareData(SimpleComboValue<Integer> model) {
                    model.set("display", model.getValue() + " Min");
                    return model;
                }
            });
            hourIntervals.setPropertyEditor(new ListModelPropertyEditor<BeanModel>("display") {
                @Override
                public String getStringValue(SimpleComboValue<Integer> model) {
                    return model.getValue() + " Min";
                }
            });

Thread Participants: 2