PDA

View Full Version : grid bind to object



easytech
19 Oct 2011, 12:37 AM
hi, i've a question;
i'm trying to bind grid to formPanel but how can i convert string value to boolean in binding process?
i would insert some checkbox in formPanel, and when a grid row is binded i would like to see che chechbox
selected or unselected

thank you

this is my code:


final FormBinding formBindings;
FormPanel panel = createForm();
formBindings = new FormBinding(panel, true);
grid= createGrid();
formBindings.setStore(grid.getStore());
grid.setPixelSize(500, 350);
grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
grid.getSelectionModel().addListener(Events.SelectionChange,
new Listener<SelectionChangedEvent<esLogin>>() {
public void handleEvent(
SelectionChangedEvent<esLogin> be) {
if (be.getSelection().size() > 0) {
formBindings.bind((ModelData) be.getSelection()
.get(0));
} else {
formBindings.unbind();
}
}
});


private FormPanel createForm() {
FormPanel panel = new FormPanel();
panel.setHeaderVisible(false);
panel.setHeight(400);

TextField<String> id = new TextField<String>();
id.setName("id");
id.setEnabled(false);
id.setFieldLabel(span + "ID</span>");
panel.add(id, new FormData(75, 22));

TextField<String> username = new TextField<String>();
username.setName("username");
username.setFieldLabel(span +"Username</span>");
panel.add(username);}

Colin Alworth
19 Oct 2011, 10:19 AM
Set a Converter for the Field in question. This can be done by creating a Converter instance with correct implementations for the two methods to convert between the field and the model, and attaching it to the FieldBinding that it belongs to in the FormBinding.

formBindings.getBindinging(myBoolField).setConverter(myStringToBooleanConverter);