On Tue, 14 Jul 2009 11:38:33 +1200, Antony Stubbs wrote:
> I'm very interested in people's suggestions of otherways of taking
> advantage of Scala to make Wicket programming easier.
We are using Scala and Wicket intensively (and the DB4O object database
as well). One thing we are working on is Wicket form generation, which
touches on ideas that are similar to those you have discussed.
This is what we can do today: consider this domain class:
class MyRectangle(var width:Int, var height:Int) extends Serializable {
def area:Double = width*height
}
we can then do:
class MyRectangleSchema extends SimpleFieldsSchema[MyRectangle](
ReadWriteFieldSchema("width", _.width, _.width = _:Int),
ReadWriteFieldSchema("height", _.height, _.height = _:Int),
ReadOnlyFieldSchema("area", _.area)
)
Above we are defining the accessors and mutators for each field except
the last which just has an accessor. We could probably use introspection
to make this much more succinct, and will likely provide this as an
option at some stage. As you see we don't use the JavaBeans conventions
as we find they are not very scala-ish, and so fully automatic
introspection is problematic.
Creating a rectangle and schema first:
val rectangle = new MyRectangle(width, height)
val schema = new MyRectangleSchema()
we use a 'builder' object to create Wicket components:
val builder = new ViewBuilder { }
We can then create a simple 'view' thus:
builder.createView("panel1", schema, rectangle)
and a simple form like this:
builder.createFormView("panel2", schema, rectangle,
new Button("submit") {
override def onSubmit = // .. do something ...
}
)
Note that the above is completely type-safe. You can also mix and match
fields from different schemas, and create schemas for aggregate objects
by embedding (sub-)schemas inside other schemas. Builders can be
overridden to provider custom components for any fields that need them.
This part of the project is still half-formed and fairly raw and
undocumented. Really only text fields are catered for. The javadoc is
here:
http://uniscala.net/uniscala-view/scaladocs/index.html
http://uniscala.net/uniscala-view-wicket/scaladocs/index.html
and is part of a larger project:
http://uniscala.net/
Apologies for lack of cross-linking between modules in the scaladoc - I
haven't worked out how to do this yet.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]