Common lift gotcha’s

Going to keep this here so maybe others will find this usefull as well and I will adding more gotcha’s here as I ran into them. So this basically is an overview to my thickness to understand lift correctly 🙂

lift Error locating template Message: Expected ‘;’
What this means is, that I copied an example of a snippet that does not work (anymore) on my computer. Using scala 2.8.1 and lift 2.2, the example of the simply lift website is like this:
<div id="main" class="lift:surround?with=default&at=content">

However it should be:
<div id="main" class="lift:surround?with=default;at=content">

Notice the amp between default and at was changed into a ‘;’
Continue reading “Common lift gotcha’s”

When trying to learn lift

use a goooood editor.

Today I was trying to get a really simple form working in lift, using the designer friendly approach. I kept on stumbling on the same kind of error:
error: value #> is not a member of java.lang.String
"#name" #> SHtml.text(name, name = _) &

and I could not figure out what was wrong with the code that I had practically copied from the simply lift web site. I kept trimming statements from my code till I had practically nothing left but a simple statement.
Continue reading “When trying to learn lift”

Access control for dwr with spring

With dwr it is possible to define methods on a bean that can be invoked from dwr-ajax calls. That much is easily to achieve following all the default tutorials on dwr on the web. However I wanted to restrict access to certain methods based on the roles that the users have. Otherwise it would be possible for certain users to call ajax methods that are not allowed for that user. But how can I change that behaviour. Looking at the documentation it is not obvious how that can be done, so I started the debugger to see how the integration really works. After some researching I came upon the DwrController that has a method call to ContainerUtil.setupDefaults. In here you can change the default behaviour classes, like the DefaultAccessControl class. So after having changed my own AccessControl implementation all I had to do is add it as parameter to the dwrController tag like so:
Continue reading “Access control for dwr with spring”

Defensive programming as anti-pattern

If you want a solid system, then null pointers can be your friend. This may seem like a contradiction since solid systems should not have null pointer exceptions but it can be a way to make your system fail fast on code that is not correct instead of covering it up. To make this more clear, take a look at the following code:<code>
if (optimizer.getStatus().equals("done") {
// do your thing, not interesting for this blog
else {
// do something else
}

Continue reading “Defensive programming as anti-pattern”