With the GWT Editor framework, any Java bean can have its data bound to a view. Data can be any bean-like object, POJO, AutoBean, or RF EntityProxy, as well as BaseModelData subclass, to facilitate migrating legacy code. We’ll discuss creating Editor subclasses and reusing them, as well as look at possible patterns for using the Drivers.
Colin Alworth has been a member of the Ext GWT community for a number of years, and has joined the team to contribute to 3.0’s successful release. With several years of Javascript, GWT, and Ext GWT experience, he brings real-world knowledge and use cases to Sencha’s next generation of GWT tools and components.
7. Users need access to data
public interface Recipe {
String getTitle();
void setTitle(String title);
String getDescription();
void setDescription(String description);
List<String> getInstructions();
void setInstructions(List<String> instructions);
}
Wednesday, November 2, 11
8. Existing 2.0 Mechanisms
Templates, XTemplates
Bindings/FormBindings and FieldBindings
Wednesday, November 2, 11
9. General Data Binding
Approaches
Observer
Update model with each change
Possibly inconsistent models
Flow Synchronization
Model always consistent
Requires explicit start and end
Wednesday, November 2, 11
10. Other goals
Interoperability with UiBinder
Validation
Local/Remote
Flexibility for customized problems/solutions
Wednesday, November 2, 11
11. GWT Editor
Framework
Wednesday, November 2, 11
13. Framework Details
Everything implements Editor (or IsEditor)
User-created editors just implement
Editor<MyModel>
Model properties edited with sub-Editors
Wednesday, November 2, 11
14. Implementation
Generates getter/setter calls as needed
If getter/setter missing, property is writeonly/readonly
If editor missing/inaccessible, no code generated
Delegates provided based on EditorDriver type selected
Allows access to EditorDriver features
Wednesday, November 2, 11
15. Editor<T>
Marker interface
‘This object edits T through its visible fields’
Other subclasses provide additional behavior
Wednesday, November 2, 11
16. Fields
Function as in 2.0
Handles validation errors from JSR-303
Errors can be local or remote
Supports field-specific validation as in 2.0
Wednesday, November 2, 11
17. Editor Driver
Binds data to and from Editors
Two provided
SimpleBeanEditorDriver
RequestFactoryEditorDriver
Wednesday, November 2, 11
18. Familiar with UiBinder?
Drivers are declared like UiBinders
Same protection for fields (not private)
Check out the UiBinder talk later
Wednesday, November 2, 11
20. Simple Editor Example
public class RecipeEditor implements IsWidget, Editor<Recipe> {
FlowLayoutContainer panel;
TextField name = new TextField();
TextField description = new TextField();
public RecipeEditor() {
panel = new FlowLayoutContainer();
panel.add(new FieldLabel(name, "Name"));
panel.add(new FieldLabel(description, "Description"));
}
@Override
public Widget asWidget() {
return panel;
}
}
Wednesday, November 2, 11
21. More complex
public interface Meal {
String getOccasion();
void setOccasion(String occasion);
Date getDate();
void setDate(Date date);
String getChef();
void setChef(String chef);
List<String> getGuests();
void setGuests(List<String> guests);
...
}
Wednesday, November 2, 11
22. public class MealEditor implements Editor<Meal>, IsWidget {
VerticalLayoutContainer panel = new VerticalLayoutContainer();
TextField occasionEditor = new TextField();
DateField dateEditor = new DateField();
SimpleComboBox<String> chef = new SimpleComboBox<String>(
new StringLabelProvider<String>());
HorizontalLayoutContainer columns = new HorizontalLayoutContainer();
RecipeEditor appetizer = new RecipeEditor();
RecipeEditor mainCourse = new RecipeEditor();
RecipeEditor dessert = new RecipeEditor();
public MealEditor() {
//...
}
@Override
public Widget asWidget() {
return panel;
}
}
Wednesday, November 2, 11
23. Editors can be Read-only
public class ReadOnlyMenuEditor implements Editor<Meal>, IsWidget {
VerticalLayoutContainer panel = new VerticalLayoutContainer();
Label occasion = new Label();
Label chef = new Label();
HorizontalLayoutContainer columns = new HorizontalLayoutContainer();
ReadOnlyRecipeEditor appetizer = new ReadOnlyRecipeEditor();
ReadOnlyRecipeEditor mainCourse = new ReadOnlyRecipeEditor();
ReadOnlyRecipeEditor dessert = new ReadOnlyRecipeEditor();
public ReadOnlyMenuEditor() {
//...
}
@Override
public Widget asWidget() {
return panel;
}
}
Wednesday, November 2, 11
24. ListStore and Editors
ListStoreEditor binds to a List property
Some details can’t be automatically handled
Adding new items
Validating one at a time or together
Saving one at a time or together
Wednesday, November 2, 11
25. RequestFactory and
Editor
SimpleBeanEditorDriver
Make sure to request.edit(model) before editing
RequestFactoryEditorDriver
Provides HasRequestContext to allow saving changes, creating
new objects
Does all editing within a single RequestContext for you
Access to update events from the server
Wednesday, November 2, 11
26. Reusablility
Editor and Driver in MVP?
Custom Editor interfaces?
Wednesday, November 2, 11