PDA

View Full Version : combobox SimpleComboBoxFieldBinding and translating error....



giovanni.puliti
24 Aug 2010, 8:18 AM
hello


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):



public class DocenteVO implements Serializable {

private Integer idDocente;
private Integer idAnagrafica;
private String siglaScuola;
private Integer idSede;
private String pathCurriculum;
private String note;
// campi non nel DB
private String nome;
private String cognome;
private Date primaData;
private Date ultimaData;
...
}



All the loading operations are fine, the grid is correctly populated as desired.
When the user click on a row in the grid i make a bind to a form for editing the data in that row.

This is accomplished using a formbindings.




FormPanel formPanel = new FormPanel();
formPanel.setScrollMode(Scroll.AUTO);
// formPanel.setFrame(false);
formPanel.setBorders(true);
formPanel.setHeaderVisible(false);

formPanel.setWidth(700);
formPanel.setLabelAlign(LabelAlign.LEFT);
formPanel.setButtonAlign(HorizontalAlignment.CENTER);
formBindings = new FormBinding(formPanel, true);
formBindings.setStore((Store) grid.getStore());



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




java.lang.ClassCastException: it.igf.igfweb.client.mvc.model.BeanModel_it_igf_igfweb_client_mvc_model_DocenteVO cannot be cast to com.extjs.gxt.ui.client.widget.form.SimpleComboValue




This is the code for the form's definition:



SimpleComboBox comboBoxDocenti = new SimpleComboBox();

comboBoxDocenti.setEmptyText("Select a teacher....");
comboBoxDocenti.setFieldLabel("Docente");
comboBoxDocenti.setDisplayField("cognomeNome");


// 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);



hLayoutContainer.add(comboBoxDocenti, new RowData(260, 1, new Margins(7, 5, 7, 0)));
FieldBinding b = new SimpleComboBoxFieldBinding(comboBoxDocenti, "cognomeNome");

b.setConverter(new Converter() {
public Object convertModelValue(Object value) {
System.out.println("convertModelValue()" + value);
DocenteVO docente = new DocenteVO();
docente.setCognome("" + value);
return docente;
}

public Object convertFieldValue(Object value) {
System.out.println("convertFieldValue()" + value);
return ((DocenteVO) value).getCognome();
}
});

formBindings.addFieldBinding(b);
formPanel.add(hLayoutContainer);

sven
24 Aug 2010, 10:06 AM
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).



ListStore store = ...... previousyl populated from the controller
store.setMonitorChanges(true);

// create the grid configuration
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

ColumnConfig studentFirstNameColumn = new ColumnConfig("nome", "Nome studente", 130);
studentFirstNameColumn.setAlignment(HorizontalAlignment.LEFT);
configs.add(studentFirstNameColumn);

ColumnConfig studentLastNameColumn = new ColumnConfig("cognome", "Cognome studente", 170);
studentLastNameColumn.setAlignment(HorizontalAlignment.LEFT);
configs.add(studentLastNameColumn);

ColumnModel columnModel = new ColumnModel(configs);

// create the grid with the Student list store
Grid grid = new Grid<BeanModel>(store, columnModel);


grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);

// set the event listener for binding the formbindings to the selected row of the grid
grid.getSelectionModel().addListener(Events.SelectionChange, new Listener<SelectionChangedEvent<BeanModel>>() {
public void handleEvent(SelectionChangedEvent<BeanModel> be) {
if (be.getSelection().size() > 0) {
ModelData selectedModel = (ModelData) be.getSelection().get(0);
formBindings.bind(selectedModel);
} else {
formBindings.unbind();
}
}
});

grid.getView().refresh(true);


this it's ok, all the student data are correctly sohwed in the grid.

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:



SimpleComboBox comboBoxDocenti = new SimpleComboBox();
comboBoxDocenti.setEmptyText("Select a teacher");
comboBoxDocenti.setFieldLabel("Teacher");

// 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:



FieldBinding b = new SimpleComboBoxFieldBinding(comboBoxDocenti, "docente");
b.setConverter(new Converter() {
public Object convertModelValue(Object value) {
System.out.println("convertModelValue()" + value);
DocenteVO docente = new DocenteVO();
docente.setCognome("" + value);
return docente;
}

public Object convertFieldValue(Object value) {
System.out.println("convertFieldValue()" + value);
return ((DocenteVO) value).getCognome();
}
});

System.out.println("Si crea il binding " + formBindings);
formBindings.addFieldBinding(b);


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!



java.lang.ClassCastException: it.igf.igfweb.client.mvc.model.BeanModel_it_igf_igfweb_client_mvc_model_TeacherVO cannot be cast to com.extjs.gxt.ui.client.widget.form.SimpleComboValue


If i use a list of strings (with the teacher's names) instead of TeacherVO list, i receive no exceptions.



comboBoxDocenti.add("Stevens");
comboBoxDocenti.add("Stewart");
comboBoxDocenti.add("White");
comboBoxDocenti.add("Chang");

.....

FieldBinding b = new SimpleComboBoxFieldBinding(comboBoxDocenti, "teacherLastName");


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.


ok this is my code (do you need all the Eclipse Project?):

this is the entrypoint class:



public class GridBinding implements EntryPoint {

private BindingPanel bindingPanel;

public void onModuleLoad() {
Viewport viewport = new Viewport();
viewport.setLayout(new BorderLayout());

LayoutContainer center = new LayoutContainer();
center.setLayout(new FitLayout());

BorderLayoutData data = new BorderLayoutData(LayoutRegion.CENTER);
data.setMargins(new Margins(5, 5, 5, 5));
bindingPanel = new BindingPanel();
center.add(bindingPanel);
viewport.add(center, data);
RootPanel.get().add(viewport);
}
}


this is the panel where i've put the grid, the form and the bindings:




public class BindingPanel extends LayoutContainer {

Grid<BeanModel> grid;
SimpleComboBox<TeacherVO> comboBoxTeachers;
private FormBinding formBindings;

public BindingPanel() {

grid = this.createGrid();
FormPanel formPanel = createForm();
formBindings = new FormBinding(formPanel, true);
formBindings.setStore((Store) grid.getStore());
FieldBinding b = new SimpleComboBoxFieldBinding(comboBoxTeachers,"teacher");

// this converter is never called - no print in the console
b.setConverter(new Converter() {
public Object convertModelValue(Object value) {
System.out.println("convertModelValue()" + value);
TeacherVO docente = new TeacherVO();
docente.setCognome("" + value);
return docente;
}

public Object convertFieldValue(Object value) {
System.out.println("convertFieldValue()" + value);
return ((TeacherVO) value).getCognome();
}
});
formBindings.addFieldBinding(b);

this.add(formPanel, new RowData(.6, 1));
this.add(grid, new RowData(.4, 1));
}

private Grid<BeanModel> createGrid() {

ListStore studentsListStore = this.getStudents();

List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

ColumnConfig studentFirstNameColumn = new ColumnConfig("nome", "Nome", 130);
studentFirstNameColumn.setAlignment(HorizontalAlignment.LEFT);
configs.add(studentFirstNameColumn);

ColumnConfig studentLastNameColumn = new ColumnConfig("cognome", "Cognome", 170);
studentLastNameColumn.setAlignment(HorizontalAlignment.LEFT);
configs.add(studentLastNameColumn);

ColumnModel columnModel = new ColumnModel(configs);
Grid grid = new Grid<BeanModel>(studentsListStore, columnModel);
grid.setAutoHeight(true);

grid.setAutoExpandColumn("lastName");
grid.setBorders(true);

grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
grid.getSelectionModel().addListener(Events.SelectionChange,
new Listener<SelectionChangedEvent<BeanModel>>() {
public void handleEvent(SelectionChangedEvent<BeanModel> be) {
if (be.getSelection().size() > 0) {
ModelData selectedModel = (ModelData) be.getSelection().get(0);
System.out.println("selectedModel "+selectedModel.get("cognome"));
formBindings.bind(selectedModel);
} else {
formBindings.unbind();
}
}
});

return grid;
}

private FormPanel createForm() {
FormPanel formPanel = new FormPanel();
formPanel.setScrollMode(Scroll.AUTO);
// formPanel.setFrame(false);
formPanel.setBorders(true);
formPanel.setHeaderVisible(false);
formPanel.setWidth(700);
formPanel.setLabelAlign(LabelAlign.LEFT);
formPanel.setButtonAlign(HorizontalAlignment.CENTER);
FormData formData = new FormData("-1");

TextField studentFirstName = new TextField();
studentFirstName.setName("nome");
studentFirstName.setFieldLabel("First Name");
formPanel.add(studentFirstName, formData);

comboBoxTeachers = new SimpleComboBox();
comboBoxTeachers.setEmptyText("Select the teacher....");
comboBoxTeachers.setFieldLabel("Teacher");
comboBoxTeachers.setDisplayField("cognomeNome");
ListStore docentiListStore = getTeachers();
comboBoxTeachers.setStore(docentiListStore);
comboBoxTeachers.setTriggerAction(TriggerAction.ALL);
comboBoxTeachers.setAutoHeight(true);
formPanel.add(comboBoxTeachers);

return formPanel;
}

private ListStore getTeachers() {
ListStore docentiListStore = new ListStore();

BeanModelFactory modelFactory = BeanModelLookup.get().getFactory(TeacherVO.class);
ListStore corsiTutorListStore = new ListStore<ModelData>();

TeacherVO theacher;
BeanModel beanmodel;

theacher = new TeacherVO("Fabrizio", "Landi");
beanmodel = modelFactory.createModel(theacher);
docentiListStore.add(beanmodel);

theacher = new TeacherVO("Lapo", "Orlissi");
beanmodel = modelFactory.createModel(theacher);
docentiListStore.add(beanmodel);

theacher = new TeacherVO("Fabio", "Loretto");
beanmodel = modelFactory.createModel(theacher);
docentiListStore.add(beanmodel);
theacher = new TeacherVO("Marco", "Derossi");
beanmodel = modelFactory.createModel(theacher);

docentiListStore.add(beanmodel);
return docentiListStore;
}

private ListStore getStudents() {

TeacherVO theacher = new TeacherVO("Fabrizio", "Landi");

BeanModelFactory modelFactory = BeanModelLookup.get().getFactory(StudentVO.class);
ListStore studentsListStore = new ListStore<ModelData>();

BeanModel beanmodel;
StudentVO student;

student = new StudentVO("giovanni", "puliti", theacher);
beanmodel = modelFactory.createModel(student);
studentsListStore.add(beanmodel);

student = new StudentVO("aldo", "fabrizi", theacher);
beanmodel = modelFactory.createModel(student);
studentsListStore.add(beanmodel);

student = new StudentVO("rosa", "rosati", theacher);
beanmodel = modelFactory.createModel(student);
studentsListStore.add(beanmodel);

student = new StudentVO("Fabio", "Filopini", theacher);
beanmodel = modelFactory.createModel(student);
studentsListStore.add(beanmodel);

return studentsListStore;
}

}




these are the Value Object beans used to populate the grdi and the combox:





public class StudentVO implements Serializable {

private String nome;
private String cognome;
private TeacherVO teacher;

public StudentVO() {
super();
}

public StudentVO(String nome, String cognome) {
super();
this.nome = nome;
this.cognome = cognome;
}

public StudentVO(String nome, String cognome, TeacherVO teacher) {
super();
this.nome = nome;
this.cognome = cognome;
this.teacher = teacher;
}

public String getNome() {
return nome;
}

public void setNome(String nome) {
this.nome = nome;
}

public String getCognome() {
return cognome;
}

public void setCognome(String cognome) {
this.cognome = cognome;
}

public String getCognomeNome() {
return this.getCognome() + " " + this.getNome();
}

public TeacherVO getTeacher() {
return teacher;
}

public void setTeacher(TeacherVO teacher) {
this.teacher = teacher;
}

}


public class TeacherVO implements Serializable {

private String nome;
private String cognome;

public TeacherVO() {
super();
}

public TeacherVO( String nome, String cognome) {
super();
this.nome = nome;
this.cognome = cognome;
}

public String getNome() {
return nome;
}

public void setNome(String nome) {
this.nome = nome;
}

public String getCognome() {
return cognome;
}

public void setCognome(String cognome) {
this.cognome = cognome;
}

public String getCognomeNome() {
return this.getCognome() + " " + this.getNome();
}

}

sven
26 Aug 2010, 1:31 AM
You have your SimpleComboBox filled with BeanModel objects. A SimpleComboBox only takes a SimpleComboValue. In your case you cannot use a SimpleComboBox as it is not simple anymore:


public static class BindingPanel extends LayoutContainer {

Grid<BeanModel> grid;
ComboBox<BeanModel> comboBoxTeachers;
private FormBinding formBindings;

public BindingPanel() {

grid = this.createGrid();
FormPanel formPanel = createForm();
formBindings = new FormBinding(formPanel, true);
formBindings.setStore((Store) grid.getStore());
FieldBinding b = new FieldBinding(comboBoxTeachers, "teacher");
formBindings.addFieldBinding(b);

this.add(formPanel, new RowData(.6, 1));
this.add(grid, new RowData(.4, 1));
}

private Grid<BeanModel> createGrid() {

ListStore studentsListStore = this.getStudents();

List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

ColumnConfig studentFirstNameColumn = new ColumnConfig("nome", "Nome", 130);
studentFirstNameColumn.setAlignment(HorizontalAlignment.LEFT);
configs.add(studentFirstNameColumn);

ColumnConfig studentLastNameColumn = new ColumnConfig("cognome", "Cognome", 170);
studentLastNameColumn.setAlignment(HorizontalAlignment.LEFT);
configs.add(studentLastNameColumn);

ColumnModel columnModel = new ColumnModel(configs);
Grid grid = new Grid<BeanModel>(studentsListStore, columnModel);
grid.setAutoHeight(true);

grid.setAutoExpandColumn("lastName");
grid.setBorders(true);

grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
grid.getSelectionModel().addListener(Events.SelectionChange, new Listener<SelectionChangedEvent<BeanModel>>() {
public void handleEvent(SelectionChangedEvent<BeanModel> be) {
if (be.getSelection().size() > 0) {
ModelData selectedModel = (ModelData) be.getSelection().get(0);
System.out.println("selectedModel " + selectedModel.get("cognome"));
formBindings.bind(selectedModel);
} else {
formBindings.unbind();
}
}
});

return grid;
}

private FormPanel createForm() {
FormPanel formPanel = new FormPanel();
formPanel.setScrollMode(Scroll.AUTO);
// formPanel.setFrame(false);
formPanel.setBorders(true);
formPanel.setHeaderVisible(false);
formPanel.setWidth(700);
formPanel.setLabelAlign(LabelAlign.LEFT);
formPanel.setButtonAlign(HorizontalAlignment.CENTER);
FormData formData = new FormData("-1");

TextField studentFirstName = new TextField();
studentFirstName.setName("nome");
studentFirstName.setFieldLabel("First Name");
formPanel.add(studentFirstName, formData);

comboBoxTeachers = new ComboBox();
comboBoxTeachers.setEmptyText("Select the teacher....");
comboBoxTeachers.setFieldLabel("Teacher");
comboBoxTeachers.setDisplayField("cognomeNome");
ListStore docentiListStore = getTeachers();
comboBoxTeachers.setStore(docentiListStore);
comboBoxTeachers.setTriggerAction(TriggerAction.ALL);
comboBoxTeachers.setAutoHeight(true);
formPanel.add(comboBoxTeachers);

return formPanel;
}

giovanni.puliti
26 Aug 2010, 1:57 AM
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...)



this is StudentVO:



public class StudentVO implements Serializable {

private String nome;
private String cognome;
private List<TeacherVO> teachers;

...


this is the binding code:




public BindingPanel() {

grid = this.createGrid();
FormPanel formPanel = createForm();
formBindings = new FormBinding(formPanel, true);
formBindings.setStore((Store) grid.getStore());
// def. the binding between the list field "teachers" in StudentVO and the ListField listTeachers
FieldBinding b = new FieldBinding(listTeachers, "teachers");

b.setConverter(new Converter() {
public Object convertModelValue(Object value) {
List teachersModel = new ArrayList();
List teachersVO = (ArrayList)value;

for (int i=0; i<teachersVO.size(); i++){
BeanModelFactory modelFactory = BeanModelLookup.get().getFactory(TeacherVO.class);
BeanModel beanmodel;
beanmodel = modelFactory.createModel(teachersVO.get(i));
teachersModel.add(beanmodel);
}
return teachersModel;
}

public Object convertFieldValue(Object value) {
// TO DO
return null;
}
});

formBindings.addFieldBinding(b);




i get this


java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.extjs.gxt.ui.client.data.ModelData


like it was a problem in converting the list of teachersModel in a flat modeldata....

how can i make this binding?

thanx a lot

Giovanni

sven
30 Aug 2010, 3:08 AM
As last time, can you please post a fully working testcase for this, so i know exactly what you are doing?

giovanni.puliti
30 Aug 2010, 3:35 AM
here there is the code:


the entry point


package it.netstudio.binding.client;

import it.netstudio.binding.client.model.TeacherVO;
import it.netstudio.binding.client.widgets.BindingPanel;
import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.data.BaseListLoader;
import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.data.BeanModelReader;
import com.extjs.gxt.ui.client.data.ListLoader;
import com.extjs.gxt.ui.client.data.LoadEvent;
import com.extjs.gxt.ui.client.data.RpcProxy;
import com.extjs.gxt.ui.client.event.LoadListener;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.Viewport;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

public class GridBinding implements EntryPoint {

private BindingPanel bindingPanel;

public void onModuleLoad() {
Viewport viewport = new Viewport();
viewport.setLayout(new BorderLayout());

LayoutContainer center = new LayoutContainer();
center.setLayout(new FitLayout());

BorderLayoutData data = new BorderLayoutData(LayoutRegion.CENTER);
data.setMargins(new Margins(5, 5, 5, 5));
bindingPanel = new BindingPanel();
center.add(bindingPanel);
viewport.add(center, data);

// aggiunge la viewport alla radice del tree di visualizzazione
RootPanel.get().add(viewport);

}


}



the binding panel



package it.netstudio.binding.client.widgets;


public class BindingPanel extends LayoutContainer {

Grid<BeanModel> grid;
ComboBox comboBoxTeachers;
ListField listTeachers;
private final GreetingServiceAsync greetingService = GWT.create(GreetingService.class);


private FormBinding formBindings;

public BindingPanel() {

grid = this.createGrid();
FormPanel formPanel = createForm();
formBindings = new FormBinding(formPanel, true);
formBindings.setStore((Store) grid.getStore());
FieldBinding b = new FieldBinding(listTeachers, "teachers");

b.setConverter(new Converter() {
public Object convertModelValue(Object value) {
List teachersModel = new ArrayList();
List teachersVO = (ArrayList)value;

for (int i=0; i<teachersVO.size(); i++){
BeanModelFactory modelFactory = BeanModelLookup.get().getFactory(TeacherVO.class);
BeanModel beanmodel;
beanmodel = modelFactory.createModel(teachersVO.get(i));
teachersModel.add(beanmodel);
}
return teachersModel;
}

public Object convertFieldValue(Object value) {
// TODO !!!
return null;
}
});

formBindings.addFieldBinding(b);

this.getStudentsFromRemote();

this.add(formPanel, new RowData(.6, 1));
this.add(grid, new RowData(.4, 1));
}

private Grid<BeanModel> createGrid() {

ListStore studentsListStore = new ListStore();//this.getStudents();

// crea la configurazione per la tabella
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

ColumnConfig studentFirstNameColumn = new ColumnConfig("nome", "Nome", 130);
studentFirstNameColumn.setAlignment(HorizontalAlignment.LEFT);
configs.add(studentFirstNameColumn);

ColumnConfig studentLastNameColumn = new ColumnConfig("cognome", "Cognome", 170);
studentLastNameColumn.setAlignment(HorizontalAlignment.LEFT);
configs.add(studentLastNameColumn);

ColumnModel columnModel = new ColumnModel(configs);
Grid grid = new Grid<BeanModel>(studentsListStore, columnModel);
grid.setAutoHeight(true);

grid.setAutoExpandColumn("lastName");
grid.setBorders(true);

grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
grid.getSelectionModel().addListener(Events.SelectionChange,
new Listener<SelectionChangedEvent<BeanModel>>() {
public void handleEvent(SelectionChangedEvent<BeanModel> be) {
if (be.getSelection().size() > 0) {
ModelData selectedModel = (ModelData) be.getSelection().get(0);

System.out.println("selectedModel "+selectedModel.get("cognome"));
formBindings.bind(selectedModel);
} else {
formBindings.unbind();
}
}
});
return grid;
}

private FormPanel createForm() {
FormPanel formPanel = new FormPanel();
formPanel.setScrollMode(Scroll.AUTO);
formPanel.setBorders(true);
formPanel.setHeaderVisible(false);
formPanel.setWidth(700);
formPanel.setLabelAlign(LabelAlign.LEFT);
formPanel.setButtonAlign(HorizontalAlignment.CENTER);
FormData formData = new FormData("-1");

TextField studentFirstName = new TextField();
studentFirstName.setName("nome");
studentFirstName.setFieldLabel("First Name");
formPanel.add(studentFirstName, formData);

listTeachers = new ListField();
listTeachers.setDisplayField("cognomeNome");
formPanel.add(listTeachers);

return formPanel;
}

private void getStudentsFromRemote(){
RpcProxy proxy = new RpcProxy() {
public void load(Object loadConfig, AsyncCallback callback) {
greetingService.findStudents(callback);
}
};

BeanModelReader reader = new BeanModelReader();
ListLoader loader = new BaseListLoader(proxy, reader);
final Store studentListStore = new ListStore(loader);
System.out.println("caricata la lista " + studentListStore);

loader.addLoadListener(new LoadListener() {
public void loaderLoad(LoadEvent le) {
if (studentListStore != null) {
grid.reconfigure((ListStore<BeanModel>) studentListStore, grid.getColumnModel());
}
}

public void loaderLoadException(LoadEvent le) {
System.out.println("loading error " + le.exception);
}
});
loader.load();
}


}



the remote GWT object


package it.netstudio.binding.server;

public class GreetingServiceImpl extends RemoteServiceServlet implements
GreetingService {



public List<StudentVO> findStudents() {
System.out.println("--- Enter findStudents");

List<TeacherVO> teachers = new ArrayList();
TeacherVO theacher;
teachers.add(new TeacherVO("Fabrizio", "Landi"));
teachers.add(new TeacherVO("Lapo", "Orlissi"));
teachers.add(new TeacherVO("Fabio", "Loretto"));
teachers.add(new TeacherVO("Marco", "Derossi"));
teachers.add(new TeacherVO("Matteo", "Franchi"));



List<StudentVO> students = new ArrayList();

StudentVO student1 = new StudentVO("giovanni", "puliti");
theacher = new TeacherVO("Fabrizio","Landi");
student1.setTeacher(theacher);
student1.setTeachers(teachers);

students.add(student1);

StudentVO student2 = new StudentVO("aldo", "fabrizi");
student2.setTeacher(theacher);
student2.setTeachers(teachers);
students.add(student2);

StudentVO student3 = new StudentVO("rosa", "rosati");
student3.setTeacher(theacher);
student3.setTeachers(teachers);
students.add(student3);


StudentVO student4 = new StudentVO("Fabio", "Filopini");
student4.setTeacher(theacher);
student4.setTeachers(teachers);

students.add(student4);
System.out.println("--- Exit findStudents");

return students;

}

@Override
public List<TeacherVO> findTeachers() {
List<TeacherVO> teachers = new ArrayList();
TeacherVO theacher;

theacher = new TeacherVO("Fabrizio","Landi");
teachers.add(theacher);

theacher = new TeacherVO("Lapo","Orlissi");
teachers.add(theacher);

theacher = new TeacherVO("Fabio","Loretto");
teachers.add(theacher);

theacher = new TeacherVO("Marco","Derossi");
teachers.add(theacher);

return teachers;
}

}







the StudentVO and TeacherVO


package it.netstudio.binding.client.model;

public class StudentVO implements Serializable {

private String nome;
private String cognome;
private TeacherVO teacher;
private List<TeacherVO> teachers;

public StudentVO() {
super();
}

public StudentVO(String nome, String cognome) {
super();
this.nome = nome;
this.cognome = cognome;
}

public StudentVO(String nome, String cognome, TeacherVO teacher) {
super();
this.nome = nome;
this.cognome = cognome;
this.teacher = teacher;
}

public String getNome() {
return nome;
}

public void setNome(String nome) {
this.nome = nome;
}

public String getCognome() {
return cognome;
}

public void setCognome(String cognome) {
this.cognome = cognome;
}

public String getCognomeNome() {
return this.getCognome() + " " + this.getNome();
}

public TeacherVO getTeacher() {
return teacher;
}

public void setTeacher(TeacherVO teacher) {
this.teacher = teacher;
}

public List<TeacherVO> getTeachers() {
return teachers;
}

public void setTeachers(List<TeacherVO> teachers) {
this.teachers = teachers;
}




}


package it.netstudio.binding.client.model;

public class TeacherVO implements Serializable {

private String nome;
private String cognome;

public TeacherVO() {
super();
}

public TeacherVO( String nome, String cognome) {
super();
this.nome = nome;
this.cognome = cognome;
}

public String getNome() {
return nome;
}

public void setNome(String nome) {
this.nome = nome;
}

public String getCognome() {
return cognome;
}

public void setCognome(String cognome) {
this.cognome = cognome;
}

public String getCognomeNome() {
return this.getCognome() + " " + this.getNome();
}

}

sven
30 Aug 2010, 3:54 AM
That is not a fully working testcase. ALso try not to use RPC but use static data in a testcase. I cannot run this testcase.

Your listTeachers ListField does not even have a store set. You should try to make it work first witout binding, and than add the binding code to it.

giovanni.puliti
30 Aug 2010, 4:32 AM
hi Sven


allyour suggestions are alreat done; BTW here there is the complete working testcase (in the case this still not run, tell me what is missing (check the attach for all source code files):

Entry point


package it.netstudio.binding.client;

import it.netstudio.binding.client.model.TeacherVO;
import it.netstudio.binding.client.widgets.BindingPanel;
import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.data.BaseListLoader;
import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.data.BeanModelReader;
import com.extjs.gxt.ui.client.data.ListLoader;
import com.extjs.gxt.ui.client.data.LoadEvent;
import com.extjs.gxt.ui.client.data.RpcProxy;
import com.extjs.gxt.ui.client.event.LoadListener;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.Viewport;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

public class GridBinding implements EntryPoint {

private BindingPanel bindingPanel;

public void onModuleLoad() {
Viewport viewport = new Viewport();
viewport.setLayout(new BorderLayout());

LayoutContainer center = new LayoutContainer();
center.setLayout(new FitLayout());

BorderLayoutData data = new BorderLayoutData(LayoutRegion.CENTER);
data.setMargins(new Margins(5, 5, 5, 5));
bindingPanel = new BindingPanel();
center.add(bindingPanel);
viewport.add(center, data);

// aggiunge la viewport alla radice del tree di visualizzazione
RootPanel.get().add(viewport);

}


}


the panel


package it.netstudio.binding.client.widgets;


import it.netstudio.binding.client.model.StudentVO;
import it.netstudio.binding.client.model.TeacherVO;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.Style.Orientation;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.binding.Converter;
import com.extjs.gxt.ui.client.binding.FieldBinding;
import com.extjs.gxt.ui.client.binding.FormBinding;
import com.extjs.gxt.ui.client.binding.SimpleComboBoxFieldBinding;
import com.extjs.gxt.ui.client.core.XTemplate;
import com.extjs.gxt.ui.client.data.BaseListLoader;
import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.data.BeanModelFactory;
import com.extjs.gxt.ui.client.data.BeanModelLookup;
import com.extjs.gxt.ui.client.data.BeanModelReader;
import com.extjs.gxt.ui.client.data.ListLoader;
import com.extjs.gxt.ui.client.data.LoadEvent;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.RpcProxy;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.FieldEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.LoadListener;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.store.Record;
import com.extjs.gxt.ui.client.store.Store;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.util.Padding;
import com.extjs.gxt.ui.client.util.Util;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Html;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.CheckBox;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.DateTimePropertyEditor;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.LabelField;
import com.extjs.gxt.ui.client.widget.form.ListField;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.extjs.gxt.ui.client.widget.layout.HBoxLayout;
import com.extjs.gxt.ui.client.widget.layout.HBoxLayoutData;
import com.extjs.gxt.ui.client.widget.layout.LayoutData;
import com.extjs.gxt.ui.client.widget.layout.MarginData;
import com.extjs.gxt.ui.client.widget.layout.RowData;
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
import com.extjs.gxt.ui.client.widget.layout.VBoxLayout;
import com.extjs.gxt.ui.client.widget.layout.HBoxLayout.HBoxLayoutAlign;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HTML;

public class BindingPanel extends LayoutContainer {

Grid<BeanModel> grid;
ComboBox comboBoxTeachers;
ListField listTeachers;
//private final GreetingServiceAsync greetingService = GWT.create(GreetingService.class);

private FormBinding formBindings;

public BindingPanel() {

grid = this.createGrid();
FormPanel formPanel = createForm();
formBindings = new FormBinding(formPanel, true);
formBindings.setStore((Store) grid.getStore());
FieldBinding b = new FieldBinding(listTeachers, "teachers");

b.setConverter(new Converter() {
public Object convertModelValue(Object value) {
List teachersModel = new ArrayList();
List teachersVO = (ArrayList) value;

for (int i = 0; i < teachersVO.size(); i++) {
BeanModelFactory modelFactory = BeanModelLookup.get() .getFactory(TeacherVO.class);
BeanModel beanmodel;
beanmodel = modelFactory.createModel(teachersVO.get(i));
teachersModel.add(beanmodel);
}
return teachersModel;
}

public Object convertFieldValue(Object value) {
// TODO !!!
return null;
}
});

formBindings.addFieldBinding(b);
this.getStudents();

this.add(formPanel, new RowData(.6, 1));
this.add(grid, new RowData(.4, 1));
}

private Grid<BeanModel> createGrid() {
ListStore studentsListStore = new ListStore();
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

ColumnConfig studentFirstNameColumn = new ColumnConfig("nome", "Nome", 130);
studentFirstNameColumn.setAlignment(HorizontalAlignment.LEFT);
configs.add(studentFirstNameColumn);

ColumnConfig studentLastNameColumn = new ColumnConfig("cognome", "Cognome", 170);
studentLastNameColumn.setAlignment(HorizontalAlignment.LEFT);
configs.add(studentLastNameColumn);

ColumnModel columnModel = new ColumnModel(configs);
Grid grid = new Grid<BeanModel>(studentsListStore, columnModel);
grid.setAutoHeight(true);

grid.setAutoExpandColumn("lastName");
grid.setBorders(true);

grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
grid.getSelectionModel().addListener(Events.SelectionChange,
new Listener<SelectionChangedEvent<BeanModel>>() {
public void handleEvent(SelectionChangedEvent<BeanModel> be) {
if (be.getSelection().size() > 0) {
ModelData selectedModel = (ModelData) be.getSelection().get(0);
System.out.println("selectedModel "+ selectedModel.get("cognome"));
formBindings.bind(selectedModel);
} else {
formBindings.unbind();
}
}
});
return grid;
}

private FormPanel createForm() {
FormPanel formPanel = new FormPanel();
formPanel.setScrollMode(Scroll.AUTO);

formPanel.setBorders(true);
formPanel.setHeaderVisible(false);
formPanel.setWidth(700);
formPanel.setLabelAlign(LabelAlign.LEFT);
formPanel.setButtonAlign(HorizontalAlignment.CENTER);
FormData formData = new FormData("-1");

TextField studentFirstName = new TextField();
studentFirstName.setName("nome");
studentFirstName.setFieldLabel("First Name");
formPanel.add(studentFirstName, formData);

listTeachers = new ListField();
listTeachers.setStore(this.getTeachers());
listTeachers.setDisplayField("cognomeNome");
formPanel.add(listTeachers);

return formPanel;
}



private ListStore getTeachers() {
ListStore docentiListStore = new ListStore();

BeanModelFactory modelFactory = BeanModelLookup.get().getFactory(TeacherVO.class);
ListStore corsiTutorListStore = new ListStore<ModelData>();

TeacherVO theacher;
BeanModel beanmodel;

theacher = new TeacherVO("Fabrizio", "Landi");
beanmodel = modelFactory.createModel(theacher);
docentiListStore.add(beanmodel);

theacher = new TeacherVO("Lapo", "Orlissi");
beanmodel = modelFactory.createModel(theacher);
docentiListStore.add(beanmodel);

theacher = new TeacherVO("Fabio", "Loretto");
beanmodel = modelFactory.createModel(theacher);
docentiListStore.add(beanmodel);
theacher = new TeacherVO("Marco", "Derossi");
beanmodel = modelFactory.createModel(theacher);

docentiListStore.add(beanmodel);
return docentiListStore;
}


private ListStore getStudents() {

List teachers = new ArrayList();
teachers.add(new TeacherVO("Fabrizio", "Landi"));
teachers.add(new TeacherVO("Lapo", "Orlissi"));

BeanModelFactory modelFactory = BeanModelLookup.get().getFactory(StudentVO.class);
ListStore studentsListStore = new ListStore<ModelData>();

BeanModel beanmodel;
StudentVO student;

student = new StudentVO("giovanni", "puliti");
student.setTeachers(teachers);
beanmodel = modelFactory.createModel(student);
studentsListStore.add(beanmodel);

student = new StudentVO("aldo", "fabrizi");
student.setTeachers(teachers);
beanmodel = modelFactory.createModel(student);
studentsListStore.add(beanmodel);

student = new StudentVO("rosa", "rosati");
student.setTeachers(teachers);
beanmodel = modelFactory.createModel(student);
studentsListStore.add(beanmodel);

student = new StudentVO("Fabio", "Filopini");
student.setTeachers(teachers);
beanmodel = modelFactory.createModel(student);
studentsListStore.add(beanmodel);

grid.reconfigure(studentsListStore, grid.getColumnModel());

return studentsListStore;
}

}

the VO beans


package it.netstudio.binding.client.model;

import java.io.Serializable;
import java.util.Date;

public class TeacherVO implements Serializable {

private String nome;
private String cognome;

public TeacherVO() {
super();
}

public TeacherVO( String nome, String cognome) {
super();
this.nome = nome;
this.cognome = cognome;
}

public String getNome() {
return nome;
}

public void setNome(String nome) {
this.nome = nome;
}

public String getCognome() {
return cognome;
}

public void setCognome(String cognome) {
this.cognome = cognome;
}

public String getCognomeNome() {
return this.getCognome() + " " + this.getNome();
}

}



package it.netstudio.binding.client.model;

import com.extjs.gxt.ui.client.data.BeanModelMarker;
import com.extjs.gxt.ui.client.data.BeanModelMarker.BEAN;

@BEAN(it.netstudio.binding.client.model.TeacherVO.class)
public interface TeacherMarker extends BeanModelMarker {

}


package it.netstudio.binding.client.model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

public class StudentVO implements Serializable {

private String nome;
private String cognome;
private TeacherVO teacher;
private List<TeacherVO> teachers;

public StudentVO() {
super();
}

public StudentVO(String nome, String cognome) {
super();
this.nome = nome;
this.cognome = cognome;
}

public StudentVO(String nome, String cognome, TeacherVO teacher) {
super();
this.nome = nome;
this.cognome = cognome;
this.teacher = teacher;
}

public String getNome() {
return nome;
}

public void setNome(String nome) {
this.nome = nome;
}

public String getCognome() {
return cognome;
}

public void setCognome(String cognome) {
this.cognome = cognome;
}

public String getCognomeNome() {
return this.getCognome() + " " + this.getNome();
}

public TeacherVO getTeacher() {
return teacher;
}

public void setTeacher(TeacherVO teacher) {
this.teacher = teacher;
}

public List<TeacherVO> getTeachers() {
return teachers;
}

public void setTeachers(List<TeacherVO> teachers) {
this.teachers = teachers;
}




}

package it.netstudio.binding.client.model;

import com.extjs.gxt.ui.client.data.BeanModelMarker;
import com.extjs.gxt.ui.client.data.BeanModelMarker.BEAN;

@BEAN(it.netstudio.binding.client.model.StudentVO.class)
public interface StudentMarker extends BeanModelMarker {

}

sven
30 Aug 2010, 4:43 AM
You need to add some equals method to your TeacherVO like this:
@Override
public boolean equals(Object o) {
if (!(o instanceof TeacherVO)) {
return false;
}
return getCognomeNome().equals(((TeacherVO)o).getCognomeNome());
}

You also need some custom FieldBinding for a ListField like this one(no converter needed):


FieldBinding b = new FieldBinding(listTeachers, "teachers") {
@Override
public void updateField(boolean updateOriginalValue) {
Object val = onConvertModelValue(model.get(property));

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




FieldBinding b = new FieldBinding(listTeachers, "teachers") {
@Override
public void updateField(boolean updateOriginalValue) {
System.out.println("updateField");
Object val = onConvertModelValue(model.get(property));
listTeachers.setSelection((List<?>) val);
}

@Override
public void onFieldChange(FieldEvent e) {
System.out.println("updateModel");
Object val = onConvertFieldValue(listTeachers.getSelection());
model.set(property, (List<?>)val);
}

};

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 {

sven
30 Aug 2010, 7:11 AM
try to add this:


listTeachers.getListView().getSelectionModel().addListener(Events.SelectionChange, new Listener<SelectionChangedEvent<D>>() {
public void handleEvent(SelectionChangedEvent<D> se) {
b.updateModel();
}
});

I have not run or tested this code.

You can probably remove the onFieldChange override.

giovanni.puliti
30 Aug 2010, 11:35 PM
now i've got a infinte loop when i select one row in the grid: maybe there is to many overrides on fieldbinding, converter etc...
Could you please provide a complete and runnig testcase? :-)

this is my code (the entry point class isn't modified):




package it.netstudio.binding.client.widgets;


import it.netstudio.binding.client.model.StudentVO;
import it.netstudio.binding.client.model.TeacherVO;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.Style.Orientation;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.binding.Converter;
import com.extjs.gxt.ui.client.binding.FieldBinding;
import com.extjs.gxt.ui.client.binding.FormBinding;
import com.extjs.gxt.ui.client.binding.SimpleComboBoxFieldBinding;
import com.extjs.gxt.ui.client.core.XTemplate;
import com.extjs.gxt.ui.client.data.BaseListLoader;
import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.data.BeanModelFactory;
import com.extjs.gxt.ui.client.data.BeanModelLookup;
import com.extjs.gxt.ui.client.data.BeanModelReader;
import com.extjs.gxt.ui.client.data.ChangeEvent;
import com.extjs.gxt.ui.client.data.ChangeEventSource;
import com.extjs.gxt.ui.client.data.ChangeListener;
import com.extjs.gxt.ui.client.data.ListLoader;
import com.extjs.gxt.ui.client.data.LoadEvent;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.PropertyChangeEvent;
import com.extjs.gxt.ui.client.data.RpcProxy;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.FieldEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.LoadListener;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.store.Record;
import com.extjs.gxt.ui.client.store.Store;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.util.Padding;
import com.extjs.gxt.ui.client.util.Util;
import com.extjs.gxt.ui.client.widget.CheckBoxListView;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Html;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.CheckBox;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.DateTimePropertyEditor;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.LabelField;
import com.extjs.gxt.ui.client.widget.form.ListField;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.extjs.gxt.ui.client.widget.layout.HBoxLayout;
import com.extjs.gxt.ui.client.widget.layout.HBoxLayoutData;
import com.extjs.gxt.ui.client.widget.layout.LayoutData;
import com.extjs.gxt.ui.client.widget.layout.MarginData;
import com.extjs.gxt.ui.client.widget.layout.RowData;
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
import com.extjs.gxt.ui.client.widget.layout.VBoxLayout;
import com.extjs.gxt.ui.client.widget.layout.HBoxLayout.HBoxLayoutAlign;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HTML;

public class BindingPanel extends LayoutContainer {

Grid<BeanModel> grid;
ComboBox comboBoxTeachers;
ListField listTeachers;
CheckBoxListView listTeachers2;

private FormBinding formBindings;

public BindingPanel() {

grid = this.createGrid();
FormPanel formPanel = createForm();
formBindings = new FormBinding(formPanel, true);
formBindings.setStore((Store) grid.getStore());



final FieldBinding b = new FieldBinding(listTeachers, "teachers") {
@Override
public void updateField(boolean updateOriginalValue) {
Object val = onConvertModelValue(model.get(property));
System.out.println("updateField - valore da onConvertModelValue:"+val);
listTeachers.setSelection((List<?>) val);
}

@Override
public void onFieldChange(FieldEvent e) {
System.out.println("onFieldChange ");
Object val = onConvertFieldValue(listTeachers.getSelection());
model.set(property, (List<?>)val);
}

@Override
public void updateModel() {
Object val = onConvertFieldValue(listTeachers.getSelection());
System.out.println("updateModel - valore da onConvertFieldValue " + val + " da mettere nella property="+property);
model.set(property, val);
}

};

b.setConverter(new Converter() {
public Object convertModelValue(Object value) {
List teachersModel = new ArrayList();
List teachersVO = (ArrayList) value;

for (int i = 0; i < teachersVO.size(); i++) {
BeanModelFactory modelFactory = BeanModelLookup.get() .getFactory(TeacherVO.class);
BeanModel beanmodel;
beanmodel = modelFactory.createModel(teachersVO.get(i));
teachersModel.add(beanmodel);
}
return teachersModel;
}

public Object convertFieldValue(Object value) {
System.out.println("Converter convertFieldValue="+value);
List teachersModel = new ArrayList();
List teachersList = (ArrayList) value;

for (int i = 0; i < teachersList.size(); i++) {
TeacherVO teacher = ((BeanModel)teachersList.get(i)).getBean();
System.out.println("teacher number:"+i+"="+teacher);
teachersModel.add(teacher);
}
return teachersModel;
}
});


listTeachers.getListView().getSelectionModel().addListener(Events.SelectionChange, new Listener<SelectionChangedEvent>() {
public void handleEvent(SelectionChangedEvent se) {
System.out.println(".....updateModel ");
b.updateModel();
}
});


formBindings.addFieldBinding(b);
this.getStudents();

this.add(formPanel, new RowData(.6, 1));
this.add(grid, new RowData(.4, 1));

this.add(new Button("Annulla", new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
System.out.println("ANNULLA");
grid.getStore().rejectChanges();
}
}));
this.add(new Button("Salva", new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
List<Record> modifiedRecords = grid.getStore().getModifiedRecords();
System.out.println("ci sono " + modifiedRecords.size() + " record modificati da salvare");

BeanModel myBeanModel;
for (int i = 0; i < modifiedRecords.size(); i++) {
Record record = modifiedRecords.get(i);
myBeanModel = (BeanModel) record.getModel();
System.out.println("myBeanModel da salvare " + myBeanModel);
}

// si committano i cambiamenti sullo store
// per renderli persistenti nella griglia
System.out.println("si committa lo store");
grid.getStore().commitChanges();

}
}));

}

private Grid<BeanModel> createGrid() {
ListStore studentsListStore = new ListStore();
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

ColumnConfig studentFirstNameColumn = new ColumnConfig("nome", "Nome", 130);
studentFirstNameColumn.setAlignment(HorizontalAlignment.LEFT);
configs.add(studentFirstNameColumn);

ColumnConfig studentLastNameColumn = new ColumnConfig("cognome", "Cognome", 170);
studentLastNameColumn.setAlignment(HorizontalAlignment.LEFT);
configs.add(studentLastNameColumn);

ColumnModel columnModel = new ColumnModel(configs);
Grid grid = new Grid<BeanModel>(studentsListStore, columnModel);
grid.setAutoHeight(true);

grid.setAutoExpandColumn("lastName");
grid.setBorders(true);

grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
grid.getSelectionModel().addListener(Events.SelectionChange,
new Listener<SelectionChangedEvent<BeanModel>>() {
public void handleEvent(SelectionChangedEvent<BeanModel> be) {
if (be.getSelection().size() > 0) {
ModelData selectedModel = (ModelData) be.getSelection().get(0);
System.out.println("selectedModel "+ selectedModel.get("cognome"));
formBindings.bind(selectedModel);
} else {
formBindings.unbind();
}
}
});
return grid;
}

private FormPanel createForm() {
FormPanel formPanel = new FormPanel();
formPanel.setScrollMode(Scroll.AUTO);
// formPanel.setFrame(false);
formPanel.setBorders(true);
formPanel.setHeaderVisible(false);
formPanel.setWidth(700);
formPanel.setLabelAlign(LabelAlign.LEFT);
formPanel.setButtonAlign(HorizontalAlignment.CENTER);
FormData formData = new FormData("-1");

TextField studentFirstName = new TextField();
studentFirstName.setName("nome");
studentFirstName.setFieldLabel("First Name");
formPanel.add(studentFirstName, formData);



listTeachers = new ListField();
listTeachers.addSelectionChangedListener(new SelectionChangedListener<ModelData>() {

@Override
public void selectionChanged(SelectionChangedEvent<ModelData> se) {
System.out.println("VALORE CAMBIATO in lista");

}
});

listTeachers.setStore(this.getTeachers());
listTeachers.setDisplayField("cognomeNome");
formPanel.add(listTeachers);

return formPanel;
}



private ListStore getTeachers() {
ListStore docentiListStore = new ListStore();

BeanModelFactory modelFactory = BeanModelLookup.get().getFactory(TeacherVO.class);
ListStore corsiTutorListStore = new ListStore<ModelData>();

TeacherVO theacher;
BeanModel beanmodel;

theacher = new TeacherVO("Fabrizio", "Landi");
beanmodel = modelFactory.createModel(theacher);
docentiListStore.add(beanmodel);

theacher = new TeacherVO("Lapo", "Orlissi");
beanmodel = modelFactory.createModel(theacher);
docentiListStore.add(beanmodel);

theacher = new TeacherVO("Fabio", "Loretto");
beanmodel = modelFactory.createModel(theacher);
docentiListStore.add(beanmodel);
theacher = new TeacherVO("Marco", "Derossi");
beanmodel = modelFactory.createModel(theacher);

docentiListStore.add(beanmodel);
return docentiListStore;
}


private ListStore getStudents() {

List teachers = new ArrayList();
teachers.add(new TeacherVO("Fabrizio", "Landi"));
teachers.add(new TeacherVO("Lapo", "Orlissi"));

BeanModelFactory modelFactory = BeanModelLookup.get().getFactory(StudentVO.class);
ListStore studentsListStore = new ListStore<ModelData>();

BeanModel beanmodel;
StudentVO student;

student = new StudentVO("giovanni", "puliti");
student.setTeachers(teachers);
beanmodel = modelFactory.createModel(student);
studentsListStore.add(beanmodel);

teachers = new ArrayList();
teachers.add(new TeacherVO("Lapo","Orlissi"));
teachers.add(new TeacherVO("Fabio","Loretto"));
teachers.add(new TeacherVO("Marco","Derossi"));
student = new StudentVO("aldo", "fabrizi");
student.setTeachers(teachers);
beanmodel = modelFactory.createModel(student);
studentsListStore.add(beanmodel);

teachers = new ArrayList();
teachers.add(new TeacherVO("Marco","Derossi"));
student = new StudentVO("rosa", "rosati");
student.setTeachers(teachers);
beanmodel = modelFactory.createModel(student);
studentsListStore.add(beanmodel);

teachers = new ArrayList();
teachers.add(new TeacherVO("Lapo","Orlissi"));
student = new StudentVO("Fabio", "Filopini");
student.setTeachers(teachers);
beanmodel = modelFactory.createModel(student);
studentsListStore.add(beanmodel);

grid.reconfigure(studentsListStore, grid.getColumnModel());

return studentsListStore;
}

}

sven
31 Aug 2010, 1:46 AM
public static class BindingPanel extends LayoutContainer {

Grid<BeanModel> grid;
ComboBox comboBoxTeachers;
ListField listTeachers;
CheckBoxListView listTeachers2;

private FormBinding formBindings;

public BindingPanel() {

grid = this.createGrid();
FormPanel formPanel = createForm();

final FieldBinding b = new FieldBinding(listTeachers, "teachers") {
@Override
public void updateField(boolean updateOriginalValue) {
Object val = onConvertModelValue(model.get(property));
System.out.println("updateField - valore da onConvertModelValue:" + val);
listTeachers.setSelection((List<?>) val);
}

public void updateModel() {
Object val = onConvertFieldValue(listTeachers.getSelection());
if (store != null) {
Record r = store.getRecord(model);
if (r != null) {
r.setValid(property, field.isValid());
r.set(property, val);
}
} else {
model.set(property, val);
}

}

};

listTeachers.getListView().getSelectionModel().addListener(Events.SelectionChange,
new Listener<SelectionChangedEvent>() {
public void handleEvent(SelectionChangedEvent se) {
System.out.println(".....updateModel ");
if (b.getModel() != null) {
b.updateModel();
}
}
});

this.getStudents();

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);

setLayout(new RowLayout());
this.add(formPanel, new RowData(1, .5));
this.add(grid, new RowData(1, .5));

this.add(new Button("Annulla", new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
System.out.println("ANNULLA");
grid.getStore().rejectChanges();
}
}));
this.add(new Button("Salva", new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
List<Record> modifiedRecords = grid.getStore().getModifiedRecords();
System.out.println("ci sono " + modifiedRecords.size() + " record modificati da salvare");

BeanModel myBeanModel;
for (int i = 0; i < modifiedRecords.size(); i++) {
Record record = modifiedRecords.get(i);
myBeanModel = (BeanModel) record.getModel();
System.out.println("myBeanModel da salvare " + myBeanModel);
}

// si committano i cambiamenti sullo store
// per renderli persistenti nella griglia
System.out.println("si committa lo store");
grid.getStore().commitChanges();

}
}));

}

private Grid<BeanModel> createGrid() {
ListStore studentsListStore = new ListStore();
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

ColumnConfig studentFirstNameColumn = new ColumnConfig("nome", "Nome", 130);
studentFirstNameColumn.setAlignment(HorizontalAlignment.LEFT);
configs.add(studentFirstNameColumn);

ColumnConfig studentLastNameColumn = new ColumnConfig("cognome", "Cognome", 170);
studentLastNameColumn.setAlignment(HorizontalAlignment.LEFT);
configs.add(studentLastNameColumn);

ColumnModel columnModel = new ColumnModel(configs);
Grid grid = new Grid<BeanModel>(studentsListStore, columnModel);

// your autoexpand column was not existend
grid.setAutoExpandColumn("nome");
grid.setBorders(true);

grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
grid.getSelectionModel().addListener(Events.SelectionChange, new Listener<SelectionChangedEvent<BeanModel>>() {
public void handleEvent(SelectionChangedEvent<BeanModel> be) {
if (be.getSelection().size() > 0) {
ModelData selectedModel = (ModelData) be.getSelection().get(0);
System.out.println("selectedModel " + selectedModel.get("cognome"));
formBindings.bind(selectedModel);
} else {
formBindings.unbind();
}
}
});
return grid;
}

private FormPanel createForm() {
FormPanel formPanel = new FormPanel();
formPanel.setScrollMode(Scroll.AUTO);
// formPanel.setFrame(false);
formPanel.setBorders(true);
formPanel.setHeaderVisible(false);
formPanel.setWidth(700);
formPanel.setLabelAlign(LabelAlign.LEFT);
formPanel.setButtonAlign(HorizontalAlignment.CENTER);
FormData formData = new FormData("-1");

TextField studentFirstName = new TextField();
studentFirstName.setName("nome");
studentFirstName.setFieldLabel("First Name");
formPanel.add(studentFirstName, formData);

listTeachers = new ListField();
listTeachers.addSelectionChangedListener(new SelectionChangedListener<ModelData>() {

@Override
public void selectionChanged(SelectionChangedEvent<ModelData> se) {
System.out.println("VALORE CAMBIATO in lista");

}
});

listTeachers.setStore(this.getTeachers());
listTeachers.setDisplayField("cognomeNome");
formPanel.add(listTeachers);

return formPanel;
}

private ListStore getTeachers() {
ListStore docentiListStore = new ListStore();

BeanModelFactory modelFactory = BeanModelLookup.get().getFactory(TeacherVO.class);
ListStore corsiTutorListStore = new ListStore<ModelData>();

TeacherVO theacher;
BeanModel beanmodel;

theacher = new TeacherVO("Fabrizio", "Landi");
beanmodel = modelFactory.createModel(theacher);
docentiListStore.add(beanmodel);

theacher = new TeacherVO("Lapo", "Orlissi");
beanmodel = modelFactory.createModel(theacher);
docentiListStore.add(beanmodel);

theacher = new TeacherVO("Fabio", "Loretto");
beanmodel = modelFactory.createModel(theacher);
docentiListStore.add(beanmodel);
theacher = new TeacherVO("Marco", "Derossi");
beanmodel = modelFactory.createModel(theacher);

docentiListStore.add(beanmodel);
return docentiListStore;
}

private ListStore getStudents() {

List teachers = new ArrayList();
teachers.add(new TeacherVO("Fabrizio", "Landi"));
teachers.add(new TeacherVO("Lapo", "Orlissi"));

BeanModelFactory modelFactory = BeanModelLookup.get().getFactory(StudentVO.class);
ListStore studentsListStore = new ListStore<ModelData>();

BeanModel beanmodel;
StudentVO student;

student = new StudentVO("giovanni", "puliti");
student.setTeachers(teachers);
beanmodel = modelFactory.createModel(student);
studentsListStore.add(beanmodel);

teachers = new ArrayList();
teachers.add(new TeacherVO("Lapo", "Orlissi"));
teachers.add(new TeacherVO("Fabio", "Loretto"));
teachers.add(new TeacherVO("Marco", "Derossi"));
student = new StudentVO("aldo", "fabrizi");
student.setTeachers(teachers);
beanmodel = modelFactory.createModel(student);
studentsListStore.add(beanmodel);

teachers = new ArrayList();
teachers.add(new TeacherVO("Marco", "Derossi"));
student = new StudentVO("rosa", "rosati");
student.setTeachers(teachers);
beanmodel = modelFactory.createModel(student);
studentsListStore.add(beanmodel);

teachers = new ArrayList();
teachers.add(new TeacherVO("Lapo", "Orlissi"));
student = new StudentVO("Fabio", "Filopini");
student.setTeachers(teachers);
beanmodel = modelFactory.createModel(student);
studentsListStore.add(beanmodel);

grid.reconfigure(studentsListStore, grid.getColumnModel());

return studentsListStore;
}

}

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

giovanni.puliti
31 Aug 2010, 5:54 AM
i've updated to the 2.2, but the exception still appears....

15:52:20.992 [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

sven
31 Aug 2010, 5:55 AM
Sorry this was my mistake now. The fix wasnt in the RC1, it will be in the final, or you can grap it from SVN if you have a support subscription.

giovanni.puliti
31 Aug 2010, 6:06 AM
when the final will be released?

sven
31 Aug 2010, 6:17 AM
http://www.sencha.com/forum/showthread.php?91913-FNR-BeanModelGenerator-ArrayLists-convert-members-to-models-only-on-get%28%29
This is the linked bugreport.

I dont want to give an exact date out, but it shuold be very soon. Probably before end of the week.