[errai-dev] Errai UI and DataBinding

Christian Sadilek csadilek at redhat.com
Tue Aug 14 23:07:57 EDT 2012


Jonathan and I discussed the benefits of the extra 2 annotations a couple of hours ago.

With the latest changes I just pushed we have the following benefits using our new approach:

-) Since @DataFields are no longer bound by default (only if marked as @Bound) we no longer have to tolerate bindings to non-existing properties. A binding to a non-existing property in errai-ui now fails at compilation/generation time. 

-) Using the programmatic data-binding API, we can now throw an exception if a user calls binder.bind(widget, "non-existing") at runtime.

-) We now support having multiple data binders in a @Templated class, as long as there's only one @AutoBound data binder.

-) It's a lot easier to understand what's going on by just reading the code.

-) And of course we have a way to specify the property we want to bind to as well as a converter class (we would have had to add an additional annotation for this anyway).

So, in short I think the extra 2 annotations are justified (at least that's what I keep telling myself :)).

Cheers,
Christian

On 2012-08-14, at 4:01 PM, Christian Sadilek <csadilek at redhat.com> wrote:

> This is implemented now.
> 
> Here's an example from the errai-ui test suite:
> https://github.com/errai/errai/blob/master/errai-ui/src/test/java/org/jboss/errai/ui/test/binding/client/res/BindingTemplate.java
> 
> It shows how to use converters and how to bind to alternative properties.
> 
> Could you give it a try by adapting your demos and see if you still like the approach before we document and release it?
> 
> Cheers,
> Christian
> 
> On 2012-08-14, at 3:48 PM, "Lincoln Baxter, III" <lincolnbaxter at gmail.com> wrote:
> 
>> Agreed, +1 for @Bound - and someone needs to fix this list to reply-all by default. I'll try.
>> 
>> On Tue, Aug 14, 2012 at 10:44 AM, Jonathan Fuerth <jfuerth at redhat.com> wrote:
>> Me too. I understand that @Inject is an imperative verb, but maybe that was a mistake in a spec we don't control. :)
>> 
>> The good news is that it reads well whether or not @Inject is also present:
>> 
>> @Inject @Bound private TextBox input;
>> @Bound private TextBox input = new TextBox("moo");
>> 
>> -Jonathan
>> 
>> PS: sorry for the earlier reply which didn't make it to the list.. I had tried to respond to the list from an account that isn't subscribed to this list.
>> From: "Lincoln Baxter, III" <lincolnbaxter at gmail.com>
>> To: "Christian Sadilek" <csadilek at redhat.com>
>> Cc: errai-dev at lists.jboss.org, "Mike Brock" <brockm at gmail.com>, "Jonathan Fuerth" <jfuerth at gmail.com>
>> Sent: Monday, August 13, 2012 1:37:04 PM
>> Subject: Re: [errai-dev] Fwd: Errai UI and DataBinding
>> 
>> 
>> I'm still leaning toward @Bound
>> 
>> On Mon, Aug 13, 2012 at 1:12 PM, Christian Sadilek <csadilek at redhat.com> wrote:
>> I agree that AutoBound is better, so the remaining question is just @Bind vs. @Bound for DataFields?
>> 
>> As adjectives:
>> 
>> @Templated
>> public class Thing extends Composite {
>> 
>>   @Inject
>>   @Bound(property="street")
>>   @DataField
>>   private TextBox input;
>> 
>>   or
>> 
>>   @Inject
>>   @Bind(property="street")
>>   @DataField
>>   private TextBox input;
>> 
>> }
>> 
>> 
>> On 2012-08-13, at 12:54 PM, "Lincoln Baxter, III" <lincolnbaxter at gmail.com> wrote:
>> 
>> I'm voting for adjectives I guess. It's typically the way that CDI Qualifiers look when functioning with @Inject. Granted, these aren't qualifiers, but they might as well be by how they behave and actually modify the result of the injection.
>> 
>> I'm 100% sure how I feel about @AutoBound - but I'm not 100% sure about @Bound.
>> 
>> 
>> As adjectives:
>> 
>> @Templated
>> public class Thing extends Composite {
>> 
>>   @Inject
>>   @Bound
>>   private TextBox input;
>> 
>>   @Inject
>>   @AutoBound
>>   private DataBinder<Model> binder;
>> 
>> }
>> 
>> 
>> As verbs:
>> 
>> @Templated
>> public class Thing extends Composite {
>> 
>>   @Inject
>>   @Bind
>>   private TextBox input;
>> 
>>   @Inject
>>   @AutoBind
>>   private DataBinder<Model> binder;
>> 
>> 
>> 
>> }
>> 
>> On Mon, Aug 13, 2012 at 11:31 AM, Christian Sadilek <csadilek at redhat.com> wrote:
>> Had the same thought. It's @Inject, so I thought @Bind would be more consistent on the data field….but I am fine either way…let's vote :)
>> 
>> On 2012-08-13, at 11:26 AM, "Lincoln Baxter, III" <lincolnbaxter at gmail.com> wrote:
>> 
>> Should it be @Bind or @Bound?
>> 
>> On Mon, Aug 13, 2012 at 10:52 AM, Christian Sadilek <christian.sadilek at gmail.com> wrote:
>> just forwarding Lincoln's reply. If there are no objections to @Bind
>> and @AutoBound, I will go ahead and implement this later today or
>> tomorrow.
>> 
>> cheers,
>> christian
>> 
>> ---------- Forwarded message ----------
>> From: Lincoln Baxter, III <lincolnbaxter at gmail.com>
>> Date: Mon, Aug 13, 2012 at 12:05 AM
>> Subject: Re: [errai-dev] Errai UI and DataBinding
>> To: Christian Sadilek <christian.sadilek at gmail.com>
>> 
>> 
>> I do think we need programmatic control over bindings. I think that
>> was one of my first questions when we implemented the @Injected
>> databinder. I agree with you that the current state is a bit too
>> "magical," and I think that the suggestions you've brough up will help
>> to eliminate that.
>> 
>> +1 to individual @Bind and also aggregate @Autobind / @Autobound annotation
>> 
>> ~Lincoln
>> 
>> On Sun, Aug 12, 2012 at 7:53 PM, Christian Sadilek
>> <christian.sadilek at gmail.com> wrote:
>> >
>> > Hi,
>> >
>> > I'd like to propose a change to our DataBinding integration in Errai
>> > UI. Basically, I think we should retire the implicit binding approach
>> > and introduce a new annotation. So, within a @Templated class that has
>> > a DataBinder<T> field, we should have the following options:
>> >
>> > 1. No binding
>> > @Inject @DataField
>> > private TextBox date;
>> >
>> > 2. Binding to model property with matching name
>> > @Inject @Bind @DataField
>> > private TextBox date;
>> >
>> > 3. Binding to model property with matching name using provided converter
>> > @Inject @Bind(converter=MyDataConverter.class) @DataField
>> > private TextBox date;
>> >
>> > 4. Binding to model property with provided name
>> > @Inject @Bind(property="lastUpdated") @DataField
>> > private TextBox date;
>> >
>> > 5. Binding to model property with provided name using provided converter
>> > @Inject @Bind(property="lastUpdated", converter=MyDataConverter.class)
>> > @DataField
>> > private TextBox date;
>> >
>> > Additionally, we could add an annotation (e.g. @AutoBind) that when
>> > present on the @Templated class causes our current behaviour. All
>> > @DataFields will be bound to model properties with matching names.
>> >
>> > I prefer this approach because just by looking at the code I get all
>> > the information I need to undersand what's going on. Our current
>> > approach seems a little too magical :).
>> >
>> > WDYT?
>> >
>> > Cheers,
>> > Christian
>> > _______________________________________________
>> > errai-dev mailing list
>> > errai-dev at lists.jboss.org
>> > https://lists.jboss.org/mailman/listinfo/errai-dev
>> 
>> 
>> 
>> 
>> --
>> Lincoln Baxter, III
>> http://ocpsoft.org
>> "Simpler is better."
>> _______________________________________________
>> errai-dev mailing list
>> errai-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/errai-dev
>> 
>> 
>> 
>> -- 
>> Lincoln Baxter, III
>> http://ocpsoft.org
>> "Simpler is better."
>> _______________________________________________
>> errai-dev mailing list
>> errai-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/errai-dev
>> 
>> 
>> 
>> 
>> -- 
>> Lincoln Baxter, III
>> http://ocpsoft.org
>> "Simpler is better."
>> 
>> 
>> 
>> 
>> -- 
>> Lincoln Baxter, III
>> http://ocpsoft.org
>> "Simpler is better."
>> 
>> _______________________________________________
>> errai-dev mailing list
>> errai-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/errai-dev
>> 
>> 
>> 
>> 
>> -- 
>> Lincoln Baxter, III
>> http://ocpsoft.org
>> "Simpler is better."
> 
> _______________________________________________
> errai-dev mailing list
> errai-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/errai-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/errai-dev/attachments/20120814/8c581aea/attachment-0001.html 


More information about the errai-dev mailing list