1. #1
    Ext User
    Join Date
    Nov 2010
    Posts
    7
    Vote Rating
    0
    pejo is on a distinguished road

      0  

    Default Combobox binding doesn't work

    Combobox binding doesn't work


    Hi all!
    I would like to bind an Employee bean which has a department property rendered with a combobx:

    Code:
                SimpleComboBox<Department> department = new SimpleComboBox<Department>();  
    	    department.setFieldLabel("Department");
    	    department.setName("department");	    
    	    department.setEditable(false);
    	    department.setAutoValidate(true);
    	    department.setTriggerAction(TriggerAction.ALL);
    	    department.add(Arrays.asList(Department.values()));
    	    department.setValueField("department");
    	    department.setSimpleValue(Enum.valueOf(Department.class, emp.getDepartment()));
    
                BeanModelFactory modelFactory = BeanModelLookup.get().getFactory(Employee.class);
                BeanModel empBeanModel = modelFactory.createModel(emp);	    
    	    formBinding.bind(empBeanModel);
    where Department is an Enum type like this:

    Code:
    	public enum Department {
    		SLS("SLS", "Sales"), ENG("ENG", "Engineer"), ACC("ACC", "Account");
    		private String code;
    		private String description;
    		Department(String code, String description) {
    			this.code = code;
    			this.description = description;}
    		public String getCode() {
    			return code;}
    		public String getDescription() {
    			return description;}
    		public String toString(){
    			return description;} }
    When I try to modify the department value, the binded bean always returns the value setted during creation. What it's wrong with this code?

    Thanks in advance!

  2. #2
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    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


    How does your Employee class look like? Have you tried to reproduce this in a small, standalone testcase implementing EntryPoint?

  3. #3
    Ext User
    Join Date
    Nov 2010
    Posts
    7
    Vote Rating
    0
    pejo is on a distinguished road

      0  

    Default


    Hi Sven,
    the example provided is yet coming from a simplified project. In attachment the source code of beans and the window class using them.

    Thanks, Pejo
    Attached Files

  4. #4
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    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


    I have not run that code, but it does not contain any binding for the SimpleComboBox

  5. #5
    Ext User
    Join Date
    Nov 2010
    Posts
    7
    Vote Rating
    0
    pejo is on a distinguished road

      0  

    Default


    True, I've missed the combobox binding. This is correct I hope:
    Code:
    SimpleComboBox<Department> department =
    new SimpleComboBox<Department>(); department.setFieldLabel("Department"); department.setName("department"); department.setEditable(false); department.setAutoValidate(true); department.setTriggerAction(TriggerAction.ALL); department.add(Arrays.asList(Department.values())); department.setValueField("department"); department.setSimpleValue(Enum.valueOf(Department.class, emp.getDepartment())); fb.addFieldBinding(new SimpleComboBoxFieldBinding(department, "department"));
    fieldSet.add(department, formData);
    But still not working:
    1. in creation setSimpleValue doesn't set the initial value
    2. in modification pressing submit button reise this exception:
    Code:
    java.lang.ClassCastException: com.extjs.gxt.samples.desktop.client.TestFormBinding$Department cannot be cast to java.lang.String
        at com.extjs.gxt.samples.desktop.client.model.BeanModel_com_extjs_gxt_samples_desktop_client_model_Employee.set(BeanModel_com_extjs_gxt_samples_desktop_client_model_Employee.java:81)
        at com.extjs.gxt.ui.client.binding.FieldBinding.updateModel(FieldBinding.java:222)
        at com.extjs.gxt.ui.client.binding.FieldBinding.onFieldChange(FieldBinding.java:242)
        at com.extjs.gxt.ui.client.binding.FieldBinding$1.handleEvent(FieldBinding.java:54)
        at com.extjs.gxt.ui.client.binding.FieldBinding$1.handleEvent(FieldBinding.java:1)
        at com.extjs.gxt.ui.client.event.BaseObservable.callListener(BaseObservable.java:178)
        at com.extjs.gxt.ui.client.event.BaseObservable.fireEvent(BaseObservable.java:86)
        at com.extjs.gxt.ui.client.widget.Component.fireEvent(Component.java:454)
        at com.extjs.gxt.ui.client.widget.form.Field.fireChangeEvent(Field.java:1035)
        at com.extjs.gxt.ui.client.widget.form.Field.onBlur(Field.java:1076)
        at com.extjs.gxt.ui.client.widget.form.TextField.onBlur(TextField.java:454)
        at com.extjs.gxt.ui.client.widget.form.TriggerField.triggerBlur(TriggerField.java:305)
        at com.extjs.gxt.ui.client.widget.form.ComboBox.triggerBlur(ComboBox.java:1438)
        at com.extjs.gxt.ui.client.widget.form.TriggerField.mimicBlur(TriggerField.java:188)
        at com.extjs.gxt.ui.client.widget.form.TriggerField$1.onAutoHide(TriggerField.java:241)
        at com.extjs.gxt.ui.client.util.BaseEventPreview.onAutoHidePreview(BaseEventPreview.java:249)
        at com.extjs.gxt.ui.client.util.BaseEventPreview.onPreviewNativeEvent(BaseEventPreview.java:145)
        at com.google.gwt.user.client.Event$NativePreviewEvent.dispatch(Event.java:195)
        at com.google.gwt.user.client.Event$NativePreviewEvent.dispatch(Event.java:1)
        at com.google.gwt.event.shared.HandlerManager$HandlerRegistry.fireEvent(HandlerManager.java:60)
        at com.google.gwt.event.shared.HandlerManager$HandlerRegistry.access$1(HandlerManager.java:53)
        at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:178)
        at com.google.gwt.user.client.Event$NativePreviewEvent.fire(Event.java:87)
        at com.google.gwt.user.client.Event$NativePreviewEvent.access$4(Event.java:73)
        at com.google.gwt.user.client.Event$.fireNativePreviewEvent(Event.java:444)
        at com.google.gwt.user.client.DOM.previewEvent(DOM.java:1284)
        at sun.reflect.GeneratedMethodAccessor37.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        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:157)
        at com.google.gwt.dev.shell.BrowserChannel.reactToMessagesWhileWaitingForReturn(BrowserChannel.java:1714)
        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:165)
        at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:264)
        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:188)
        at sun.reflect.GeneratedMethodAccessor22.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        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:157)
        at com.google.gwt.dev.shell.BrowserChannel.reactToMessagesWhileWaitingForReturn(BrowserChannel.java:1714)
        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:165)
        at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:264)
        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:188)
        at sun.reflect.GeneratedMethodAccessor22.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        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:157)
        at com.google.gwt.dev.shell.BrowserChannel.reactToMessages(BrowserChannel.java:1669)
        at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:401)
        at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222)
        at java.lang.Thread.run(Thread.java:619)
    
    
    Looks like as it expects a Department enum type and not String. I have to use a Converter?

    Thanks!

  6. #6
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    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


    I have not tested this code:
    Code:
     fb.addFieldBinding(new SimpleComboBoxFieldBinding(department, "department") {
            @Override
            protected Object onConvertFieldValue(Object value) {
              return ((SimpleComboValue<Department>) value).getValue().getCode();
            }
    
            @Override
            protected Object onConvertModelValue(Object value) {
              return super.onConvertModelValue(Department.valueOf((String) value));
            }
          });

  7. #7
    Ext User
    Join Date
    Nov 2010
    Posts
    7
    Vote Rating
    0
    pejo is on a distinguished road

      0  

    Default


    Great, it's work fine!

    Thanks!

Similar Threads

  1. GXT 2.1.1 ComboBox Field Binding does not work
    By navi75 in forum Ext GWT: Discussion
    Replies: 6
    Last Post: 15 Jul 2012, 7:17 PM
  2. Replies: 9
    Last Post: 23 Dec 2008, 7:25 AM
  3. My Combobox doesn't work well.
    By mashiki in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 14 Feb 2008, 8:22 AM
  4. ComboBox onChange doesn't work?
    By gelleneu in forum Ext 1.x: Help & Discussion
    Replies: 2
    Last Post: 16 Aug 2007, 4:31 AM

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..."