Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: [1.2.2] Problem with ModelProcessor when binding BeanModels

  1. #1
    Ext User
    Join Date
    Jun 2008
    Posts
    365

    Default [1.2.2] Problem with ModelProcessor when binding BeanModels

    - GXT version : 1.2.2
    - GWT version : 1.5.3
    - Hosted mode
    - Operating System : Windows XP
    - Detailed description of the problem :
    I have a form panel I bind to a bean (MyBean). MyBean contains a bean (Customer) attribute. I use a model processor to customize the display of the Customer.

    Open the combo box. Choose a value. Click outside the combo box (so that the combo box losts the focus) -> the combo box field text is cleared. I think the value is ok but not the rawValue. It looks like the "customName" property is not copied by the binding.

    Here is the sample code :
    Code:
    public class Test implements EntryPoint {
    
        private static void getCustomers(AsyncCallback<List<Customer>> callback) {
            ArrayList<Customer> res = new ArrayList<Customer>();
            res.add(new Customer("Me", "hoho", 27));
            res.add(new Customer("Someone", "hoho", 72));
            callback.onSuccess(res);
        }
    
        public void onModuleLoad() {
            Viewport viewport = new Viewport();
    
            RpcProxy proxy = new RpcProxy() {
                @Override
                public void load(Object loadConfig, AsyncCallback callback) {
                    getCustomers(callback);
                }
            };
            ListLoader loader = new BaseListLoader(proxy, new BeanModelReader());
            ListStore<BeanModel> store = new ListStore<BeanModel>(loader);
    
            final MyBean myBean = new MyBean();
    
            final ComboBox<BeanModel> comboBox = new ComboBox<BeanModel>();
    
            comboBox.setFieldLabel("Profile");
            comboBox.setDisplayField("customName");
            comboBox.getView().setModelProcessor(new ModelProcessor<BeanModel>() {
                @Override
                public BeanModel prepareData(BeanModel model) {
                    if (model != null)
                        model.set("customName", ((Customer) model.getBean())
                                .getName()
                                + "!!");
                    return model;
                }
            });
            comboBox.setStore(store);
    
            final FormPanel loginPanel = new FormPanel() {
                @Override
                protected void beforeRender() {
                    super.beforeRender();
                    add(comboBox);
                    addButton(new Button("Show profile name", new SelectionListener<ButtonEvent>(){
                        @Override
                        public void componentSelected(ButtonEvent ce) {
                            if(myBean.getProfile() != null)
                                Window.alert("profile name : "+myBean.getProfile().getName());
                        }
                    }));
                }
            };
            FormBinding binding = new FormBinding(loginPanel, false);
            binding.addFieldBinding(new FieldBinding(comboBox, "profile"));
            //MyBean myBean = new MyBean();
            BeanModel myBeanModel =
                    BeanModelLookup.get().getFactory(MyBean.class).createModel(
                            myBean);
            binding.bind(myBeanModel);
            loginPanel.layout();
            viewport.add(loginPanel);
    
            RootPanel.get().add(viewport);
    
        }
    
    }
    
    public class MyBean{
        public Customer getProfile() {
            return profile;
        }
        public void setProfile(Customer profile) {
            this.profile = profile;
        }
        private Customer profile;
    }
    
    @BEAN(MyBean.class)
    public interface MyBeanModel extends BeanModelMarker {
    
    }
    Last edited by sdc; 5 Feb 2009 at 12:24 AM. Reason: move myBean declaration, add a button, reopen

  2. #2
    Sencha Premium Member
    Join Date
    Sep 2007
    Posts
    13,976

    Default

    I dont know what you are trying to do here but "profile" is never set:

    Code:
    binding.addFieldBinding(new FieldBinding(comboBox, "profile"));

  3. #3
    Ext User
    Join Date
    Jun 2008
    Posts
    365

    Default

    Quote Originally Posted by sven View Post
    I dont know what you are trying to do here but "profile" is never set:

    Code:
    binding.addFieldBinding(new FieldBinding(comboBox, "profile"));
    Well...................... it is set by the binding when you select a value in the combobox. "profile" is the name of a MyBean attribute.
    Look at the code, I've added an alert.
    Now :
    - Select a value in the combobox
    - click outside
    - the combobox field is now empty
    - click the button : you'll see that the profile is well set

    By the way, this was working in 1.2.1 or 1.2.0.

  4. #4
    Sencha Premium Member
    Join Date
    Sep 2007
    Posts
    13,976

    Default

    Set the displayfield of the combobox to "name"

  5. #5
    Ext User
    Join Date
    Jun 2008
    Posts
    365

    Default

    Hi Sven,

    Thanks for the support. However, I don't want to use the field "name" for the display. In my app, I need to use a ModelProcessor to customize the display.

  6. #6
    Sencha Premium Member
    Join Date
    Sep 2007
    Posts
    13,976

    Default

    The problem is that getValue returns the customer object, not the model you are editing. So the "customName" field is missing. So you cannot introduce a new field in runtime. Describe in more details what you are trying to do and we can may come up with a solution.

  7. #7
    Sencha Premium Member
    Join Date
    Sep 2007
    Posts
    13,976

    Default

    You could for exampel override onModelChange of FieldBinding to do nothing.

  8. #8
    Ext User
    Join Date
    Jun 2008
    Posts
    365

    Default

    Quote Originally Posted by sven View Post
    The problem is that getValue returns the customer object, not the model you are editing.
    More precisely : getValue() returns a BeanModel wrapping the Customer bean.

    So the "customName" field is missing. So you cannot introduce a new field in runtime.
    This is the problem.
    The BeanModel SHOULD contains the "customName" field because the ModelProcessor SHOULD add the field.

  9. #9
    Ext User
    Join Date
    Jun 2008
    Posts
    365

    Default

    By the way, the same test case works with gxt 1.2

  10. #10
    Ext User
    Join Date
    Jun 2008
    Posts
    365

    Default

    Well. I have put some breakpoints in Eclipse which can help.
    Here what is going on :

    1 - the ComboBox lost the focus,

    2 - the ComboBox fires a change event (in Field.onBlur(ComponentEvent be))

    3 - the FieldBinding handles the event (in FieldBinding.onFieldChange(FieldEvent e))

    4 - the FieldBinding updates the model : it sets the field (combobox) value into the
    "profile" property (Customer/BeanModel) of the model (MyBean/BeanModel). This is in the FieldBinding.updateModel() method, line 178.

    5 - At this point, the val argument is OK and contains the "customName" property in its RpcMap ! But after the set call, ((BeanModel)model.get("profile")).get("customName") returns null... Something wrong in the BeanModelGenerator ? Or expected behaviour ? Anyway, this wouldn't be a problem for me if the set method was not firing itself a new ChangeEvent, because now the FieldBinding updates the field (should this really happen ?) and then it erases the displayed text value.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •