1. #1
    Sencha User
    Join Date
    Oct 2010
    Location
    Kuşadası/Aydın/Turkey
    Posts
    94
    Vote Rating
    0
    TrojanMyth is on a distinguished road

      0  

    Default How to combobox databinding.

    How to combobox databinding.


    Hi;

    Code:
                Form = new FormPanel();
            Form.setHeaderVisible(false);
            Form.setFrame(true);
            
                Kodu = new TextBox<String>();
                Kodu.setName("kodu");
                Kodu.setFieldLabel("Kodu");
                Kodu.setUpperCase(true);
    
    
                Adi = new TextBox<String>();
                Adi.setName("adi");
                Adi.setFieldLabel("Adı");
                Adi.setUpperCase(true);
                
                ListStore<ModelData> comboStore = new ListStore<ModelData>();
                comboStore.add(StateModel.getStateModel(StateModel.StateModelType.Department));
                comboStore.commitChanges();
                State = new ComboBox<ModelData>();
                State.setFieldLabel("Durumu");
                State.setDisplayField("name");
                State.setName("state");
                State.setValueField("state");
                State.setEditable(false);
                State.setForceSelection(true);
                State.setTriggerAction(ComboBox.TriggerAction.ALL);
                State.setStore(comboStore);
                State.setValue(comboStore.getAt(0));
                
                
           Form.add(Kodu,new FormData("-3"));
           Form.add(Adi,new FormData("-3"));
           Form.add(State,new FormData("-3"));
           getContent().add(Form, new FitData());
           setHeight(230);
    
           
    
                RpcProxy<String> formProxy = new RpcProxy<String>() {
    
                    @Override
                    protected void load(Object loadConfig, AsyncCallback<String> callback) {
                        if(getCurrentId()!=0){
                            SERVICE.getDepartment(getCurrentId(), callback);
                        }
                    }
                };
    
           ModelType formFieldType = new ModelType();
           formFieldType.setRoot("datatable");
           DataField idField = new DataField("departman_id", "departman_id");
           idField.setType(Long.class);
    
           formFieldType.addField(idField);
           formFieldType.addField("kodu", "kodu");
           formFieldType.addField("adi", "adi");
           DataField stateField = new DataField("state", "state");
           stateField.setType(Integer.class);
           formFieldType.addField(stateField);
    
           
                JsonLoadResultReader<ModelData> reader = new JsonLoadResultReader<ModelData>(formFieldType);
                FormLoader = new BaseListLoader<BaseListLoadResult<ModelData>>(formProxy,reader);
    
                FormLoader.addLoadListener(new LoadListener(){
    
                @Override
                public void loaderLoadException(LoadEvent le) {
                    IlonMessageBox.alert(le.exception);
                }
                });
    
                FormStore = new ListStore<ModelData>(FormLoader);
                FormStore.addStoreListener(new StoreListener<ModelData>(){
    
                    @Override
                    public void storeDataChanged(StoreEvent<ModelData> se) {
                        if(se.getStore()!=null){
                            if(se.getStore().getModels()!=null){
                                getBinding().bind(se.getStore().getModels().get(0));
                            }
                        }
                    }
                });
    
                
           Binding = new FormBinding(Form, true);
           Binding.setStore((Store)FormStore);
    
           FieldBinding koduBinder = new FieldBinding(Kodu, "kodu");
           FieldBinding adiBinder = new FieldBinding(Adi, "adi");
           FieldBinding stateBinder = new FieldBinding(State, "state");
    
           Binding.addFieldBinding(koduBinder);
           Binding.addFieldBinding(adiBinder);
           Binding.addFieldBinding(stateBinder);
    Code:
       public static List<BaseModelData> getStateModel(StateModelType type){
            List<BaseModelData> result = new ArrayList<BaseModelData>();
            switch(type){
                case Department:
                    BaseModelData aktifData = new BaseModelData();
                    aktifData.set("name", "Aktif");
                    aktifData.set("state", 1);
                    result.add(aktifData);
                    BaseModelData pasifData = new BaseModelData();
                    pasifData.set("name", "Pasif");
                    pasifData.set("state", 0);
                    result.add(pasifData);
                    break;
            }
            return result;
        }
    This code do Binding Kodu and Adi field but dont binding State combobox.

    How to binding they combobox.

  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


    Have you implemented equals correctly on your state model? The code looks like you have not.

    How does a model look like you are going to bind?

  3. #3
    Sencha User
    Join Date
    Oct 2010
    Location
    Kuşadası/Aydın/Turkey
    Posts
    94
    Vote Rating
    0
    TrojanMyth is on a distinguished road

      0  

    Default


    Code:
    @Override
        public void onFind(ApplicationWindowOperation o) {
            final DepartmentFindWindow find = new DepartmentFindWindow(true);
            find.addOperationHandler(new ApplicationFindWindowOperationHandler() {
    
                @Override
                public void onSelect(ApplicationFindWindowOperation o) {
                    if(o.getResultData()!=null){
                        try{
                            long selectedId = Long.parseLong(o.getResultData().toString());
                            if(selectedId!=0){
                                getFormLoader().load();
                            }
                        }
                        catch(Exception e){
                            IlonMessageBox.alert("Bilinmeyen Hata",e.getMessage());
                        }
                    }
                }
    
                @Override
                public void onNew(ApplicationFindWindowOperation o) {
                    //throw new UnsupportedOperationException("Not supported yet.");
                }
    
                @Override
                public void onClose(ApplicationFindWindowOperation o) {
                    find.hide();
                }
    
                @Override
                public void onDetail(ApplicationFindWindowOperation o) {
                    //throw new UnsupportedOperationException("Not supported yet.");
                }
            });
            find.show();
        }
    Returned JSON Data
    Code:
    {datatable:[{departman_id:6,kodu:'BY',adi:'Bayi',state:'1'}]}
    this code its true work and load a department info and two textbox bind data. My problem is with Combobox. Combo box dont select empty.

  4. #4
    Sencha User
    Join Date
    Oct 2010
    Location
    Kuşadası/Aydın/Turkey
    Posts
    94
    Vote Rating
    0
    TrojanMyth is on a distinguished road

      0  

    Default


    HTML Code:
    00:01:40,918  [ERROR] Uncaught exception escaped
    <pre>java.lang.ClassCastException: java.lang.Integer cannot be cast to com.extjs.gxt.ui.client.data.ModelData
        at com.extjs.gxt.ui.client.widget.form.ComboBox.setValue(ComboBox.java:1)
        at com.extjs.gxt.ui.client.binding.FieldBinding.updateField(FieldBinding.java:207)
        at com.extjs.gxt.ui.client.binding.FieldBinding.bind(FieldBinding.java:82)
        at com.extjs.gxt.ui.client.binding.Bindings$1.execute(Bindings.java:91)
        at com.google.gwt.user.client.CommandExecutor.doExecuteCommands(CommandExecutor.java:310)
        at com.google.gwt.user.client.CommandExecutor$2.run(CommandExecutor.java:205)
        at com.google.gwt.user.client.Timer.fire(Timer.java:141)
        at sun.reflect.GeneratedMethodAccessor31.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.GeneratedMethodAccessor19.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)</pre>
    Casting Exception. How must to use modeldata. I want a simple model for all combo and edit (and for database).

  5. #5
    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


    What does your code look like? You should really take the time and post a fully working testcase that implements EntryPoint. For this you should use local data.

  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


    As far as i understand is: Your model holds an Integer that represents a State, while your combobox can only handle ModelData. This means that before you bind the value, you need to convert it to a ModelData and before writing it back to the model, you need to convert it back to a Integer. The FieldBInding class has a Converter support exactly for this.

  7. #7
    Sencha User
    Join Date
    Oct 2010
    Location
    Kuşadası/Aydın/Turkey
    Posts
    94
    Vote Rating
    0
    TrojanMyth is on a distinguished road

      0  

    Default


    Sorry, I think I couldn't tell what I want to say. I will write what i want to say with java.

    This is My Form.
    Code:
                Kodu = new TextBox<String>();
                Kodu.setName("kodu");
                Kodu.setFieldLabel("Kodu");
                Kodu.setUpperCase(true);
    
    
                Adi = new TextBox<String>();
                Adi.setName("adi");
                Adi.setFieldLabel("Adı");
                Adi.setUpperCase(true);
                
                ListStore<ModelData> comboStore = new ListStore<ModelData>();
                comboStore.add(StateModel.getStateModel(StateModel.StateModelType.Department));
                comboStore.commitChanges();
                State = new ComboBox<ModelData>();
                State.setFieldLabel("Durumu");
                State.setDisplayField("name");
                State.setName("state");
                State.setValueField("state");
                State.setTypeAhead(true);
                State.setEditable(false);
                State.setForceSelection(true);
                State.setTriggerAction(ComboBox.TriggerAction.ALL);
                State.setStore(comboStore);
                State.setValue(comboStore.getAt(0));
    
                
                
           Form.add(Kodu,new FormData("-3"));
           Form.add(Adi,new FormData("-3"));
           Form.add(State,new FormData("-3"));
    This is my model type
    Code:
    ModelType formFieldType = new ModelType();
           formFieldType.setRoot("datatable");
           DataField idField = new DataField("departman_id", "departman_id");
           idField.setType(Long.class);
    
           formFieldType.addField(idField);
           formFieldType.addField("kodu", "kodu");
           formFieldType.addField("adi", "adi");
           DataField stateField = new DataField("state", "state");
           stateField.setType(Integer.class);
           formFieldType.addField(stateField);
    This is my Bind field parameters
    Code:
    FieldBinding koduBinder = new FieldBinding(Kodu, "kodu"); //TextBox
           FieldBinding adiBinder = new FieldBinding(Adi, "adi");//TextBox
           FieldBinding stateBinder = new FieldBinding(State, "state");//Combobox<ModelData>
    State Combobox is data visible or hide mode container.

    This is My State Model
    Code:
       public static List<BaseModelData> getStateModel(StateModelType type){
            List<BaseModelData> result = new ArrayList<BaseModelData>();
            switch(type){
                case Department:
                    BaseModelData aktifData = new BaseModelData();
                    aktifData.set("name", "Aktif");
                    aktifData.set("state", 1);
                    result.add(aktifData);
                    BaseModelData pasifData = new BaseModelData();
                    pasifData.set("name", "Pasif");
                    pasifData.set("state", 0);
                    result.add(pasifData);
                    break;
            }
            return result;
        }
    get State model returned list<modeldata> because i want use a simple data model and dynamical model everywhere.

    My Problem is

    state field data is integer in my database. I want bind direct db data. How i need to use combobox and model. Can u send sample pls.

  8. #8
    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


    Than you need to use a converter as explained in my last reply.

  9. #9
    Sencha User
    Join Date
    Oct 2010
    Location
    Kuşadası/Aydın/Turkey
    Posts
    94
    Vote Rating
    0
    TrojanMyth is on a distinguished road

      0  

    Default


    This my returned json data

    Code:
    {datatable:[{departman_id:3,kodu:'TKN',adi:'Teknik Servis',state:1}]}

  10. #10
    Sencha User
    Join Date
    Oct 2010
    Location
    Kuşadası/Aydın/Turkey
    Posts
    94
    Vote Rating
    0
    TrojanMyth is on a distinguished road

      0  

    Default


    Code:
    import com.extjs.gxt.ui.client.binding.Converter;
    import com.extjs.gxt.ui.client.binding.FieldBinding;
    import com.extjs.gxt.ui.client.data.ModelData;
    import com.extjs.gxt.ui.client.widget.form.ComboBox;
    import com.extjs.gxt.ui.client.widget.form.Field;
    
    /**
     *
     * @author akartal
     */
    public class ComboboxFieldBinding extends FieldBinding {
    
        public ComboboxFieldBinding(Field field, String property) {
            super(field, property);
            if(field instanceof ComboBox){
                final ComboBox<ModelData> combo = (ComboBox<ModelData>)field;
                setConverter(new Converter() {
    
                    @Override
                    public Object convertFieldValue(Object value) {
                        if(value instanceof ModelData){
                            ModelData val = (ModelData)value;
                            return val.get(combo.getValueField());
                        }
                        else{
                            return value;
                        }
                    }
    
                    @Override
                    public Object convertModelValue(Object value) {
                        return combo.getStore().findModel(combo.getValueField(), value);
                    }
    
                });
            }
        }
            
    
    }
    Ok thanx sven. This is work. And sorry for my english.

Similar Threads

  1. Ext Databinding
    By Greffin in forum Ext 3.x: User Extensions and Plugins
    Replies: 4
    Last Post: 23 Jan 2010, 2:21 PM
  2. ComboBox field and databinding
    By ninja in forum Ext GWT: Help & Discussion (1.x)
    Replies: 1
    Last Post: 4 Sep 2008, 6:46 AM
  3. [Solved] Formpanel, JsonReader and databinding
    By overgaardmortern in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 30 Aug 2008, 1:20 AM
  4. FormPanel and DataBinding problem
    By murilofaria in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 16 Jun 2008, 12:49 PM
  5. Json formfields DataBinding
    By ollieno in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 10 Oct 2007, 11:09 AM

Thread Participants: 1

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..." hd porno faketaxi