Tuesday, May 25, 2010

Concise Groovy

The power of closures

Filter duplicates and write to csv file
def set = new HashSet();

new File("C:/temp/no2.csv").eachLine {
  line -> set.add(line)

new File("C:/temp/no3.csv").withWriter {writer, count = 0 ->
  set.each {
    element ->
    if (count < set.size()) writer.append(",")

Wednesday, May 19, 2010

"Autologin" with Seam

Sometimes we've just built our login routine in the traditional Seam way using the Identity instance wired to a form like:

In order to login the user automatically when i.e. clicking on a link we just need to add the following to pages.xml and to our Authenticator

So now the parameters will be automatically propagated by Seam and we can programmatically call login() on the Identity instance. In this example the URL would be /login.seam?username=xxx&password=xxx

Of course we could use the URL rewriter to make Seam react to more RESTful URLs. See the docs for that.