PDA

View Full Version : How can I Bind a ComboBox with the selection Model of a Grid..??



RaulDM
15 Jun 2009, 2:59 AM
I have a Grid which is holding Person Records.

My Person Bean:

public class person{
int id;
String name;
Department dept;

public void setId(String id){id=id;}
public String getId(){return id;}
public void setName(String name){name = name;}
public String getName(){return name;}
public void setDepartment(Department d){dept=d;}
public Department getDepartment(){return dept;}
}

My Department Class

public class Department{
int id;
int name;

public void setId(String id){id=id;}
public String getId(){return id;}
public void setName(String name){name=name;}
public String getName(){return name;}
}

Now my Grid is holding the list of Persons and it has columns like:

Person Name Department Name
John CSE
Mac ENT
Robert Instrumentation

And I have a form which is bind with this Grid via form Binding and it looks like

Person Name: <-----------------Text Field
Department name : <-----------------Combox Box

I bind the Grid with my form and when I click the row contains Robert, the Person Name field of my Form displays Robert, but the Department name Combo does not showing anything.

The Depart name combo has been populated with the Bean Model data created from the Department Bean, and thus it holds the name of all the existing departments.

Now what I want to do is to when I select a row in my Grid, say Row having the person name Robert, the Department name Combo Box should force its selection to the department to which Robert belongs.

How can I do this..??

Plz help...!!

Raul

sven
15 Jun 2009, 3:17 AM
Please take a look at the examples. Exactly this is handled there.

RaulDM
15 Jun 2009, 4:56 AM
Hello sven,

Thanks for your reply.

I had checked the Basic Binding example provided in the gxt-2.0-m3 bundle. But it was a bit simpler than my issue.

I have two ListStore<BeanModel> s,
First one PersonStore<BeanModel> to populate my Grid and I had attached the same with my FormBinding as

Grid<BeanModel> grid = createEditorGrid();
grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
grid.getSelectionModel().addListener(Events.SelectionChange, new Listener<SelectionChangedEvent<BeanModel>>() {
publicvoid handleEvent(SelectionChangedEvent<BeanModel> be) {
if (be.getSelection().size() > 0) {
formBindings.bind((ModelData) be.getSelection().get(0));
} else {
formBindings.unbind();
}
}
});
add(grid);
FormPanel panel = createForm();
formBindings = new FormBinding(panel, true);
formBindings.setStore((Store<BeanModel>) grid.getStore());
add(panel);

Now i have a DepartmentStore<BeanModel> to populate my ComboBox in my form panel as

(Note: I am unable to use SimpleComboBox with my ListStore<BeanModel> generated from Department Bean):

final ComboBox<BeanModel> dept = new ComboBox<BeanModel>();
dept.setStore(deptStore);
dept.setDisplayField("name");
dept.setValueField("dept_id");
dept.setFieldLabel("Department");
dept.setTypeAhead(true);
dept.setEditable(false);
//FieldBinding b = new SimpleComboBoxFieldBinding(dept, "name");
// formBindings.addFieldBinding(b);
left.add(dept);

Now the problems are:

1. I am not able to attach the DepartmentStore with the Combo field if I use a SimpleComboBox.

2. If somehow, I would make it possible to attach the ListStore with the SimpleComboBox, then my question is, will it become possible to change the selection of the ComboBox each time I select a different Row in my Grid...?? The new Combo field Selection will be of course related to the concerned person in the selected row of the Grid.

Now if I want to assign a different department to a Person the Combo should also provide this facility. My form will do the rest of the modification part.



If I clear at my issue….. plz put some help…!!



Regards
Raul.