PDA

View Full Version : FormBinding with Registry



fspab
5 Jun 2009, 5:01 AM
I'm trying to do a FormBinding with a model that is taken from the Registry.

The code would be something like:


final String SELECTED_CLASSIFICATION = "selectedClassification";

//Register the selected classification
BaseModel selectedClassification = new BaseModel();
Registry.register(SELECTED_CLASSIFICATION, selectedClassification);

//Add selection information
FormPanel selectionPanel = new FormPanel();

TextField selectedClassificationField = new TextField();
selectedClassificationField.setName("selectedClassification");
selectedClassificationField.setFieldLabel("Selected classification");

//bind selected classification to the field
FormBinding classificationBinding = new FormBinding(selectionPanel);

classificationBinding.bind(selectedClassification);
classificationBinding.addFieldBinding(new FieldBinding(selectedClassificationField, "name"));

selectionPanel.add(selectedClassificationField);

Button testButton = new Button("Change classification", new SelectionListener<ButtonEvent>() {

@Override
public void componentSelected(ButtonEvent ce) {
BaseModel newModel = (BaseModel) Registry.get(SELECTED_CLASSIFICATION);
//Do something with newModel
Registry.register(SELECTED_CLASSIFICATION, newModel);
}
});
selectionPanel.add(testButton);
When doing like that, the changes made to the model are not reflected in the field.
I'm using the GXT MVC so the call to the "Change Classification" button would be done from somewhere else.

Any idea what is wrong or how this could be done?

A solution that is working is to remove the binding and to also pass the field through the Registry, but this is really an ugly solution...