On Fri, Oct 3, 2008 at 3:12 PM, Arthur Kalmenson <[EMAIL PROTECTED]> wrote:
> What's you're take on a data binding framework for GWT?
I have written a data binding framework for myself that I think could
be generally useful. I am currently busy documenting it, and soon
(hopefully in the next business day or two) I intend to post it here
for review. I'm very excited by the ease of use I have managed to
extract from my library and I hope it can help others, too. Perhaps
the most exciting single feature is @Calculate, demonstrated here:
public interface PersonForm extends Form<Person> {
Field<Person, String> getFirstName();
Field<Person, String> getLastName();
@Calculate("${firstName} + \" \" + ${lastName}")
Formula<Person, String> getFullName();
}
// in widget code:
PersonForm form = GWT.create(PersonForm.class);
Person me = new Person("Ian", "Petersen");
BoundForm<Person> boundForm = form.bindTo(me);
BoundField<Person, String> firstName = boundForm.bind(form.getFirstName());
BoundField<Person, String> lastName = boundForm.bind(form.getLastName());
BoundFormula<Person, String> fullName = boundForm.bind(form.getFullName());
Grid grid = new Grid(3, 2);
grid.setWidget(0, 0, firstName.getLabel());
grid.setWidget(0, 1, firstName.getEditor().asWidget());
grid.setWidget(1, 0, lastName.getLabel());
grid.setWidget(1, 1, lastName.getEditor().asWidget());
grid.setWidget(2, 0, fullName.getLabel());
grid.setWidget(2, 1, fullName.getViewer().asWidget());
The result is a 2 x 3 grid. The left-most cells will contain labels
for the right-most cells. The two calls to getEditor().asWidget()
result in text boxes that can edit the first- and last-name fields,
respectively. The exciting bit (for me) is that the Viewer created
for the last cell will automatically update itself as the user changes
the values in the text boxes. The magic mostly happens in a generator
and @Calculate can accept just about any Java expression that you can
cram between a return and a ;.
Ian
--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---