[Play 2.0.x] Getting rid of the trailing slash in a pattern matched url

Posted by & filed under Uncategorized.

Let’s take a look at the following Play! Scala artifacts… Routes (note the option ‘?’ in the regex) GET /contacts/$filter<[a..z]?> controllers.Contacts.list(filter: Option[String]) Contacts controller def list(filter: Option[String]) = Action { // … } View template <a href=”@routes.Contacts.list(None)”>All</a> <a href=”@routes.Contacts.list(Some(“a”))”>A</a> Then… …the reverse routes of the view template are expanded to /contacts/ and /contacts/a. To get… Read more »

Extension Methods in Java, Xtend & Scala

Posted by & filed under Coding.

Extending the functionality of classes is trivial: simply use inheritance and add new methods. There are cases where extending classes by inheritance is not practicable, e.g. given final classes like java.lang.String. Another simple way of extending the functionality of classes is applying methods defined somewhere else. Modern languages like Xtend and Scala provide convenient syntax… Read more »

Inspired by treehugger.js

Posted by & filed under Coding.

A few months ago I saw an impressive presentation of treehugger.js – a handy JavaScript library for representing, analyzing and transforming tree data structures, performing program processing. As a little finger exercise I started to write a similar library for Scala. Here is the first shot:

Reverse Code Generation

Posted by & filed under Coding.

Background A few days ago my companion Hendy Irawan shared with me his thoughts about accelerating the creation of code generators. The common way of writing a code generator (e.g. based on Xtext) is Writing a prototype of (parts of) your program. Identifying the parts of your code to be generated. This leads to the… Read more »

Url Path Binding w/o Boilerplate

Posted by & filed under Coding.

Update: Just noticed that I forgot to mention, that the following line has to be added to the main method of project/Build.scala: routesImport += “binders._” Regarding the previous post, it makes sense to provide a special Enumeration type which is bindable by the Play framework:

Play with Scala: Url Path Binding

Posted by & filed under Coding.

With Play and Scala, type-safe web development is a breeze. The following example shows how Play parses url paths and derives values of an Scala enumeration. There are two valid url paths: /signup/company and /signup/sales. Other url paths, such as /signup/unknown are properly handled as invalid. Play handles routes with variable parts like /signup/:account. In… Read more »