Play framework impressions

The play framework is a web action-based framework that allows you to create web applications in fast and simple way. The play framework can start fast and reload your java classes in a fast way without restarting your application. Play focuses on developer productivity and targets RESTful architectures. Play doesn’t use a java webserver to start the application so the webserver starts up fast, but it does use many standard java libraries, like jpa with hibernate. Another nice feature of play is that you can start it up in test mode and then you have an embedded selenium test available to you.

Models
You can use existing jpa entities or create new ones extending from the Model that play provides. Extending this base class will get you an id and a number of find methods that can be used as static methods.
The properties are set as public fields in these model classes. This looks like a no-no to any experienced java developer, but if you think about it a bit more, this may not be such an awfull thing. Most models that I have seen are nothing more then a bunch of getters and setters for some properties. So why not make them public. The play framework will create the getters and setters and will use them, however this is done at run time.

Continue reading “Play framework impressions”

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”

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"

spring configurations

In larger projects you often end up with some settings which should be stored in configuration files. These are mostly settings that won’t change much during the development lifecycle but can change based on which machine the application is running on. A good example for this is the database connect string that the application should connect on. A developer machine can connect to a mysql instance where as the production machine can connect to a large scale oracle database. When deploying the application to production, the deployers should then always check to see if these settings are still corrrect. This can cause a lot of errors in a real time envrionment.
Continue reading “spring configurations”

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”

Scala constructors

Overview of “getting my hands dirty with scala”

Since a while now, I have been trying to get into scala, because I think its a very interesting language with promising concepts. But as usual the scala books just kept lying around, waiting for a better time to come by. But waiting on better times will never result in anything so I decided to just start doing it. In this blog I will post the things that I ran into, hopefully for others to learn from, or otherwise, just for me to read and laugh about again.
Continue reading “Scala constructors”