i've some problems with bindings with SimpleComboBox.
there is a grid populated with a listStore with data from a database. Any row in the grid it's a student (a StudentVO value object bean) wich contain a list of theacers (a DocenteVO value Object bean):

in the form all the textfield are correclty displayed following the binding
defined. On of the fields in the form is a combobox, containing all the teachers avalaible
to the class the student belong.

I'm not able to make the correct binding beetween the Student and the teacherList: when i click on
a row in the grid (this event will cause a binding from the student and the teacghers), i receive this exception

// retrieve the teachersListStore created via the Controller
teachersListStore = Registry.get("teachersListStore");
// link the teachersListStore to the combo
// this will run ok
comboBoxDocenti.setStore(docentiListStore);
comboBoxDocenti.setTriggerAction(TriggerAction.ALL);

You should try to post a fully working testcase that implements EntryPOint and shows exactly what you are doing.

giovanni.puliti

25 Aug 2010, 5:27 AM

Hi Sven

You should try to post a fully working testcase that implements EntryPOint and shows exactly what you are doing.

it's actually a bit time wasting to reproduce a complete testcase (and maybe to cofusing and time wasting for you to read all of it). Let me show the basic steps of my code: i think it's a problem con conversion from my value object to SimpleComboValue, since when i use strings i receive no exception.

In the main panel there is grid bounded to a ListStore: that store is populated (via an RPC call) with StudentVO value object beans. Any StudentVO instance contain a TheacherVO bean (actually the teacher of the class teh student belong to).

On the right of the grid there is a form with some text field and a combobox: the textfields are linked to the grid's selected row via the formbindings: this it's working well.
the combobox is populated with a binding to a list store full of TeacherVO:

// the combo will display the TeacherVO.lastName
comboBoxDocenti.setDisplayField("lastName");
// bind the combobox with the teacherVO list
docentiListStore = Registry.get("docentiListStore");
comboBoxDocenti.setStore(docentiListStore);

In this part there is no errors: the combobox will display all the shool's teachers; now i want to connect the studentVO.teacherVO (the selected teacher for that student) to the selected value in the SimpleCombo: this is the code:

when i click on a grid's row the selected student will populate the form, and the combo should select the teacher from the list corresponding to the StudentVO.teacher.... but this will cause an excetpion, since GXT it's not able to convert the TeacherVO to a SimpleComboValue!

in this case selecting a value from the combo, will set the teacher's last name in StudentVO.teacherLastName (but this is just setting a flat attribute in StudentVO.... i need to modify the link beetween StudentVO and TeacherVO)

So what i've to do to convert a TeacherVO to a SimpleValue?

thanx
G

sven

25 Aug 2010, 5:38 AM

it's actually a bit time wasting to reproduce a complete testcase (and maybe to cofusing and time wasting for you to read all of it). Let me show the basic steps of my code: i think it's a problem con conversion from my value object to SimpleComboValue, since when i use strings i receive no exception.

It is actually the complete opposite. Having a complete runnable testcase that everybody can run will probably give you the correct code within a very short time. Now here the people have to first understand what you do, than try to recreate your code without knowing your code and than fixing it. I dont know many people that want to do that ;)

Creating a testcase would take you a few minutes, as you already have all the code needed. You should always create testcases for problems as it is much easier to help you.

giovanni.puliti

26 Aug 2010, 12:58 AM

hi Sven

It is actually the complete opposite. Having a complete runnable testcase that everybody can run will probably give you the correct code within a very short time. Now here the people have to first understand what you do, than try to recreate your code without knowing your code and than fixing it. I dont know many people that want to do that ;)

Creating a testcase would take you a few minutes, as you already have all the code needed. You should always create testcases for problems as it is much easier to help you.

i'm using the SimpleCombobox because i need to make a binding in the form between the StudentVO and the TeacherVO. this is accomplished by usgin the object SimpleComboBoxFieldBinding isn't?

the use case is abount editing all the data of a student: all text field attributes of a student are bounded using a formbindings, but there is the case of the relation student-teacher...
the user need to make the assignement of the desiderd teacher to the student, selecting the TeacherVO from a list (actually the combobox).

how can i do that? and if the relation between student and teacher where many - to - many? is it possible to make a bindings in a form (the student's editing form) between the student's data and a multiselection combobox (like in http://www.sencha.com/examples/explorer.html#checkboxlistview)

sven

26 Aug 2010, 2:35 AM

. this is accomplished by usgin the object SimpleComboBoxFieldBinding isn't?
SimpleComboBoxFieldBinding is a special binding for a SimpleComboBox. You can simple use a FieldBinding as shown in the code i posted. You dont have to use a SimpleComboBoxFieldBinding.

the user need to make the assignement of the desiderd teacher to the student, selecting the TeacherVO from a list (actually the combobox).
Isnt the code i posted actually doing that? Or do i missunderstand your question?

giovanni.puliti

30 Aug 2010, 2:49 AM

Hi Sven

sorry, your posted code was exactly what i was looking for.
Now something little more difficult (this is actualliy what i need to do):
in the previous post the model was base on a 1-to-1 relation (in StudentVO there is only 1 TeacherVO), but in my real model the relation is 1-to-n (in StudentVO there is a list of TeacherVO); I need also to allow a multi selection in the Teacher's list (e.g. using a multiselect ListField);

How can i code this mapping?
i make some modifications on the original code, using a FieldList instead of a combobox, but a get a ClassCastExc.....
i crate also a Converter (following some other posts on this forum,but it seems not working...)

listTeachers.setSelection((List<?>) val);
}
};
This is jsut doing the displaying part, not the saving.

giovanni.puliti

30 Aug 2010, 5:00 AM

thanx Sven

this finally work correctly. Please tell me what i've to do for the saving part.
What about using a CheckBoxListView for allowing the multiselect? i've noticed it's not possible to use the field binding with a CheckBoxListView..... there is another way?
In alternative, is it possible to customize the graphical aspect of the ListField to emulate the checkbox functionality?

Giovanni

giovanni.puliti

30 Aug 2010, 7:03 AM

I'm trying to activate the bidirectional binding (referring to the Sven's previous post, the "saving part" of the code) i've tried to do this, but nothig appens...

The method onFieldChange() is never called..... maybe this is because (from class FieldBinding's javadoc) the model not support the bidirectional binding?

Any suggestion?

/**
* A two-way binding between a ModelData and Field instance. The binding will be
* 1-way when the bound model does not support change events.
*
* @see ModelData
* @see Field
*/
@SuppressWarnings("unchecked")
public class FieldBinding {

formBindings = new FormBinding(formPanel, true);
// this needs to be called AFTER getStudents as you switch the stores
// there.
formBindings.setStore((Store) grid.getStore());
formBindings.addFieldBinding(b);

I removed the unneeded parts of your code.
I also fixed the wrong autoexpand column on your grid.

You used a RowData but never set a RowLayout. I fixed this. Also adjusted the RowData and removed the autoheight from the grid.

Your FormBinding was set to the wrong store. You are reconfiguring your grid later with a new store.

I tested this against 2.2 RC1.

giovanni.puliti

31 Aug 2010, 5:25 AM

tested now on my PC: when i click on a list item to change the selection, i still got this exception:
(note i'm currently using GXT 2.1.1 on GWT 2.0.x Java6@Osx)

Any Idea?

15:22:11.584 [ERROR] [gridbinding] Uncaught exception escaped
java.lang.ClassCastException: it.netstudio.binding.client.model.BeanModel_it_netstudio_binding_client_model_TeacherVO cannot be cast to it.netstudio.binding.client.model.TeacherVO
at it.netstudio.binding.client.model.BeanModel_it_netstudio_binding_client_model_TeacherVO.get(BeanModel_it_netstudio_binding_client_model_TeacherVO.java:25)
at com.extjs.gxt.ui.client.widget.form.ModelPropertyEditor.getStringValue(ModelPropertyEditor.java:47)
at com.extjs.gxt.ui.client.widget.form.ModelPropertyEditor.getStringValue(ModelPropertyEditor.java:1)
at com.extjs.gxt.ui.client.widget.form.Field.setValue(Field.java:919)
at com.extjs.gxt.ui.client.widget.form.ListField.setSelection(ListField.java:198)
at it.netstudio.binding.client.widgets.BindingPanel$1.updateField(BindingPanel.java:111)
at com.extjs.gxt.ui.client.binding.FieldBinding.updateField(FieldBinding.java:187)
at com.extjs.gxt.ui.client.binding.FieldBinding.onModelChange(FieldBinding.java:241)
at com.extjs.gxt.ui.client.binding.FieldBinding$2.modelChanged(FieldBinding.java:61)
at com.extjs.gxt.ui.client.data.ChangeEventSupport.notify(ChangeEventSupport.java:37)
at com.extjs.gxt.ui.client.data.BaseModel.notify(BaseModel.java:109)
at com.extjs.gxt.ui.client.data.BaseModel.notifyPropertyChanged(BaseModel.java:157)
at it.netstudio.binding.client.model.BeanModel_it_netstudio_binding_client_model_StudentVO.set(BeanModel_it_netstudio_binding_client_model_StudentVO.java:97)
at com.extjs.gxt.ui.client.store.Record.set(Record.java:286)
at it.netstudio.binding.client.widgets.BindingPanel$1.updateModel(BindingPanel.java:120)
at it.netstudio.binding.client.widgets.BindingPanel$2.handleEvent(BindingPanel.java:135)
at it.netstudio.binding.client.widgets.BindingPanel$2.handleEvent(BindingPanel.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.selection.AbstractStoreSelectionModel.fireSelectionChange(AbstractStoreSelectionModel.java:379)
at com.extjs.gxt.ui.client.widget.selection.AbstractStoreSelectionModel.doMultiSelect(AbstractStoreSelectionModel.java:297)
at com.extjs.gxt.ui.client.widget.selection.AbstractStoreSelectionModel.doSelect(AbstractStoreSelectionModel.java:309)
at com.extjs.gxt.ui.client.widget.ListViewSelectionModel.handleMouseDown(ListViewSelectionModel.java:146)
at com.extjs.gxt.ui.client.widget.ListViewSelectionModel.handleEvent(ListViewSelectionModel.java:86)
at com.extjs.gxt.ui.client.widget.ListViewSelectionModel.handleEvent(ListViewSelectionModel.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:462)
at com.extjs.gxt.ui.client.widget.Component.onBrowserEvent(Component.java:878)
at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1307)
at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1263)
at sun.reflect.GeneratedMethodAccessor16.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:1713)
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.GeneratedMethodAccessor13.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:1668)
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:637)

sven

31 Aug 2010, 5:26 AM

Yes, that got fixed in 2.2. You will need to update to that version

giovanni.puliti

31 Aug 2010, 5:33 AM

thanx very much sven. i'll check asap.

- On the download page, the 2.2 is a RC1.... is a stable version?

- is it possible to use a CheckBoxListView for allowing the multiselect instead of a listfield?

G

sven

31 Aug 2010, 5:35 AM

A listfield support multiply selections. Just hit ctrl as you would normally do on windows.

giovanni.puliti

31 Aug 2010, 5:42 AM

yes i know, but the users (giving us the GUI requirements) feels to be more confortable with check box items to select..... it's just an usability request