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”

Lift and form’s

Learning scala, or trying to learn scala, was the first step for trying out the scala lift web framework. There are a number of tutorials on lift on the web and they are very needed, since the initial code for a lift framework application is a bit daunting to say the least. On the liftweb website there are 2 books that you can download for free, exploring lift and simply lift. Exploring lift is complete but also steps over some nitty-gritty details, which are more complete in simply lift, so for best understanding you should try to read both books.

In simply lift, there are some examples for form processing. This starts out really simple and gets more complex as you progress. Initially in the html code a form tag was used. However once the example progresses towards a statefull snippet, the form tag is replaced by a div tag. See copied example:
<div id="main" class="lift:surround?with=default&at=content">
<div> Continue reading "Lift and form’s"

Getting values from a map

As I slowly progress in Scala I was trying to get values from a map and if not found return some kind of default value. Being still a java-head, I tried it initially to do it like the following:

var templates:Map[String, String] = Map()

... some code to fill the templates...

// wont compile
def locateTemplate(name: String) : String = {
    if (templates.get(name) == null) {
        templates.get(name)
    }
    else {
        // by default return the name itself
        name
    }
}

Continue reading “Getting values from a map”

Scala Constructors with Scala 2.8

Last week at the devoxx, I watched a presentation on “What’s new in Scala 2.8” and one thing I really liked in this presentation (and thus in Scala 2.8) was the notion of named and default parameters. What this means is that if you have a number of parameters, you can give them default values, so if they are not filled in when being called, the default values will be set as the parameters. This is something that is already present in a number of languages, but was (and still is) missing in java. Luckily my new preferred language to be has this now as well. When using this correctly, the code can become even more readable, since not all parameters have to be specified.
Continue reading “Scala Constructors with Scala 2.8”