On Wed, Jun 8, 2011 at 3:27 PM, tetsuo <[email protected]> wrote:
> If you only keep the static methods, there is no point extending the class.
>
> If you keep both setters and static methods, it would be *very* confusing.
>
> For example:
>
> add(new TextField("name").add(new AttributeModifier("class",
> "foo").overwrite("width","100%"));
>
> yes, Eclipse would show a warning (for accessing a static method from
> an instance), but nobody I know besides me pays much attention to
> compiler warnings.
>
> I don't think we should just use setters, since it makes it much more
> verbose. I'm ok with the DSL, but only if it makes the code more
> terse, not more verbose. If I have to call both 'append()' and
> 'separator(" ")', I'd rather call them 'setMode(APPEND)' and
> 'setSeparator(" ")', but I'd much more pleased with 'overwrite(" ")'.
>
How your preferences are less verbose ?!
They are several characters longer.

<irony>
As well-behaving Java developer you must use set and get for all
accessor/mutator methods
</irony>
But this is just a habit and a weird standard for tools, not for
humans. I doubt someone ever will try to create UI for editing
AttributeModifier, or going to persist it with JPA/... If there is
such tool then it can always use field access instead of method
access.

As I said both ways are fine for me.
>
>
>
> On Wed, Jun 8, 2011 at 10:10 AM, Martijn Dashorst
> <[email protected]> wrote:
>> You can still use the constructors, nobody is taking that away. The
>> idea of these static methods is that they convey meaning
>> better—enhancing the readability.
>>
>> add(new TextField("name",
>>                 new PropertyModel<String>(personModel, "name"))
>>            .add(new AttributeModifier("class", "foo")
>>                               .setEditMode(EditMode.OVERWRITE)
>>                               .setSeparator(" ")
>>                               .setAddAttributeIfNotExists(true)));
>>
>> versus
>>
>> add(new TextFIeld("name",
>>                 new PropertyModel<String>(personModel, "name"))
>>            .add(AttributeModifier.overwrite("class", "foo")));
>>
>> Martijn
>>
>> On Wed, Jun 8, 2011 at 2:52 PM, tetsuo <[email protected]> wrote:
>>> I'd prefer calling the constructor instead of static methods. It makes
>>> it clear that you are creating a new instance, and how you could
>>> extend the class if you needed to.
>>>
>>> Oh, and 'for' is a reserved keyword :)
>>>
>>> Tetsuo
>>>
>>>
>>>
>>> On Wed, Jun 8, 2011 at 9:02 AM, Martijn Dashorst
>>> <[email protected]> wrote:
>>>> On Wed, Jun 8, 2011 at 1:02 PM, James Carman
>>>> <[email protected]> wrote:
>>>>> What about the separator?
>>>>
>>>> I'm thinking of ditching the separator as a constructor parameter, and
>>>> defaulting to ' ' (space). Is there anyone who uses any other value
>>>> for the separator? The attribute modifier will have a setter for the
>>>> separator, so that you can do AttrbuteModifier.append("onclick",
>>>> "return false;").setSeparator(";");
>>>>
>>>> As for the fluent api... we can add that as a bonus. I'd like to keep
>>>> the shorthand for  AttributeModifier.append/prepend/overwrite
>>>>
>>>> Might I suggest the following fluent api:
>>>>
>>>> AttributeModifier.for("class").overwrites().value("error");
>>>> AttributeModifier.for("class").appends().value(Model.of("error"));
>>>> AttributeModifier.for("onclick").prepends().value("if(!confirm('Sure?'))
>>>> return false;');
>>>>
>>>> Or perhaps:
>>>>
>>>> AttributeModifier.for("class").puts("error");
>>>> AttributeModifier.for("class").appends(Model.of("error"));
>>>> AttributeModifier.for("onclick").prepends("if(!confirm('Sure?'))
>>>> return false;');
>>>>
>>>> Martijn
>>>>
>>>> --
>>>> Become a Wicket expert, learn from the best: http://wicketinaction.com
>>>>
>>>
>>
>>
>>
>> --
>> Become a Wicket expert, learn from the best: http://wicketinaction.com
>>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

Reply via email to