The Artima Developer Community
Sponsored Link

Java Buzz Forum
Fluent Interface for Wicket

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Wilfred Springer

Posts: 176
Nickname: springerw
Registered: Sep, 2006

Wilfred Springer is a Software Architect at Xebia
Fluent Interface for Wicket Posted: Feb 15, 2009 9:22 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Wilfred Springer.
Original Post: Fluent Interface for Wicket
Feed Title: Distributed Reflections of the Third Kind
Feed URL: http://blog.flotsam.nl/feeds/posts/default/-/Java
Feed Description: Anything coming to my mind having to do with Java
Latest Java Buzz Posts
Latest Java Buzz Posts by Wilfred Springer
Latest Posts From Distributed Reflections of the Third Kind

Advertisement
Last week I learned Wicket. This week, I am looking at Wicket 1.4rc2. I remember having looked at what would have been Wicket 2.0 in the past. Wicket 1.4 introduces Generics again.

Now, the first time I saw the angle brackets appearing in our source code, I was in shock. Then I started to think... This could actually be good.

Now, looking at a simple example of how all of this work, you probably don't get all that excited. Admittedly, having the IDE and compiler helping you to add the proper type of validators is sort of ok, if you like that kind of thing. (I do!) But then again, the amount of brackets (type parameters) appearing in your code is not really cool. Especially for a framework that is proud of it's limited use of angle brackets. (XML, that is.)

Here's an example:
  form.add(new TextField<Date>("whatever", new PropertyModel<Date>(event, "date"))
.add(DateValidator.maximum(new Date())));
While I was thinking about this, I started to wonder if a fluent interface would be able to take care of all of this through type inference. And I think it does. I quickly prototyped a fluent FormBuilder, and this is what the above example looks alike now:
addTextField("whatever")
.forModelOfType(Date.class)
.validatedBy(DateValidator.maximum(new Date()))
.forProperty("date").of(event)
.to(form);
And all the brackets are magically gone again... Now don't be fooled by the simplicity here. The compiler and IDE will support you in exactly the same way as in the first code example. You will not be able to add an IValidator type of validator, as the screenshot below illustrates. 

Now, I have to say that the current incarnation of this fluent API is less than great. One of the things I should have done already - but haven't done yet - is to be able to drop .forModelOfType(...) in case you pass the property type in the forProperty(...) construct. So something like this: .forProperty("date").ofType(Date.class).of(event). But that's details. In general, I think this could work. What do you think?

Read: Fluent Interface for Wicket

Topic: Android SDK 1.1 Previous Topic   Next Topic Topic: Will the real WebKit please standup

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use