I've been playing around with the idea of creating some wicket
extensions in Scala for developing wicket with Scala...
For example, taking advantage of Scala's functional language, we can
mixin the following function and class to make models easier:
def f(gtr: => String):Fodel = new Fodel(gtr, null)
implicit def func2Fodel1(gtr: => String):Fodel = new Fodel(gtr, null)
implicit def func2Fodel2(gtr: () => String):Fodel = new Fodel(gtr(),
null)
/**
* @see http://technically.us/code/x/the-escape-hatch
* @author Nathan Hamblen
* @author Antony Stubbs
*/
class Fodel(value: => String, x:(String) => Unit) extends
Model[String] {
override def getObject:String = value
override def setObject(s:String):Unit = x(s)
}
And then we can substitute read only models with:
form.add(new Label("helloworld", f(name)))
or
form.add(new Label("helloworld3", ()=> name ))
or read/write models with:
form.add(new TextField("name", f(name, name = _) ) )
name = _
is short hand for
x => name = x
and if we want something even easier, with a simple custom component:
class SLabel(id:String, gtr: => String) extends Label[String](id, new
Fodel(gtr, null))
we can write:
form.add(new SLabel("helloworld2", name))
instead of
form.add(new Label("helloworld", new PropertyModel[String](this,
"name")))
All the inline single statement functions you see here can also be
used for longer code blocks as well.
Is there any interest in things like this? I was thinking about
putting it up on git-hub.
I'm very interested in people's suggestions of otherways of taking
advantage of Scala to make Wicket programming easier.
One thing I'd love to solve, but don't think you with Scala - there's
no concept of properties yet unfortunately, so there's no nice read/
write model solution.
Regards,
Antony Stubbs
Talk to me about Wicket, Spring, Maven consulting, small scale
outsourcing to Australasia and India and Open Source development!
Check out the Spring Modules fork at http://wiki.github.com/astubbs/spring-modules
! We've just done the first release of the project in over a year!
Website: http://sharca.com
Blog: http://stubbisms.wordpress.com
Linked In: http://www.linkedin.com/in/antonystubbs
Podcast: http://www.illegalargument.com