søndag 11. juli 2010

This blog is moving

Find new and old posts over here: http://blog.trondbjerkestrand.no/

torsdag 1. juli 2010

ScalaQuery Documentation

The team is taking some time to write documentation for the ScalaQuery project by Stefan Zeiger, we do it partly for own reference and partly to promote ScalaQuery.

You can find it at: http://wiki.github.com/tbje/scala-query

onsdag 9. juni 2010

Emacs and file encoding

Change encoding in buffer:
C-x RET f coding-system RET

Read file again with another encoding:
C-x RET c coding-system RET M-x revert-buffer RET

torsdag 22. april 2010

ReCaptcha Lift integration

"reCAPTCHA is a free CAPTCHA service that helps to digitize books, newspapers and old time radio shows." - reCaptcha.net

I had some issues making it work well with Lift so I decided to blog about it (sharing is caring).

The standard approach described here (code under) didn't show up in Opera so I chose to go with the AJAX API.




The "html"




Recaptcha.create() brings up the captcha. When the form is submitted we call setHidden() to set the hidden lift form elements.

<lift:msgs/> displays messages set with S.error.

On the server side we verify the response by calling the reCaptcha API.



Binding using the -%> operator binds the attributes from the html (here the essential id attributes).

The following was tested on Google App Engine and might need some modifications to work other places.

mandag 12. april 2010

Random unique hash in Scala

I use this code to generate random unique keys for invites:

mandag 29. mars 2010

CometActor: What happens when render fails

I stumbled upon a strange bug the other day. My CometActor would just render the template content even if it seemed impossible looking at the render method. After some investigation I found out that the database layer swallowed an exception.



I also found out that when the render fails, it will display defaultXml which if you do some binding is not valid xml.

I later came to that overriding defaultXml must be a good way to make my CometActor more fault tolerant.



The problem in the code above is that we try to bind using the newly defined defaultXml and not the NodeSeq from the template. How can we get hold of template xml? Easy we just call super.defaultXml:

Adding scripts to CometActor in Lift

If you ever wondered how to include javascript in the head section or how to include other content in the body when using a CometActor the solution is to override fixedRender:



The resulting html:



Notice that Lift is using two div's, and during a reRender(false) only the inner one is updated.


Unfortunately the Alert doesn't take a JsCmd, I would prefer writing: