Showing posts with label playframework. Show all posts
Showing posts with label playframework. Show all posts

Tuesday, October 22, 2013

Updating existing Playframework project from 2.1 to 2.2

It is very trivial but got few minutes wasted for not reading the play migration documentation...

I had my old project in 2.1 and wanted to updated to newer version 2.2.0.

So here I am after downloading latest version of Playframework. Subsequent to downloading, I updated the class path to latest version and changed the version in my plugins.sbt file. Dreaming it will work :(.

First Error
-------------
unresolved dependency: play#sbt-plugin;2.2.0: not found
-------------

Simple enough to understand that some plugin name has been changes. Previous plugin name was play but now it's com.typesafe.play. Hence the new line looks something like below.

// Use the Play sbt plugin for Play projects
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")

After updating this I was confident that I will be able to work on my project now but NOPE... Same old exception. After a while realized that new version of Play comes with new SBT version. So had to update build.properties file to 0.13.0

Update line in build.properties file
-------------------------------------------
sbt.version=0.13.0

This time I was super confident that I will feel the taste of success but same error greeted me with smile. I had to come out of play prompt and did "play clean-all" and then started the play console again. 

BOOM!! Could compile it with new version..

-Manisha



Wednesday, October 9, 2013

Byte Code Enhancement: Eliminates noise for you

In one of our pairing session, I wrote couple of Model classes and public fields. You guessed it right my pair started lecturing me on encapsulation and why it's important to hide the internal representation of an object.  :D 

I am not going into the details of why and what was wrong with exposing the public field. We all know it and pretty much following the javaBean specification all the while for a reason. In gist, we want to save our internal state and don't want anybody to destroy it unintentionally or on purpose.

I assured him that Playframework will takecare of his concerns and will replace the public fields reference with getters and setters right after your original code is compiled by slightly rewriting the byte code.

Playframework helps you eliminate all these boilerplate code where you’d normally write a simple getter and setter, and allows you to just use public fields whenever you DON'T require special logic in a getter and/or setter.

You don’t have to use it, if you don’t want to, you can just create your own getters and setters and Playframework won’t touch your classes.

I would recommend to think little longer if you decide to export or re-use your class outside your application because Playframework does it's magic after class is complied therefore if you ever change your mind to use setters and getters, you have to rewrite your client code. 

Have fun
Manisha

Monday, September 9, 2013

main.scala.html fails to load with end tags

I encountered very interesting issues today when I was adding twitter bootstrap to our project. I downloaded the bootstap and added the files into my public directory. Subsequently I added below lines into our main template since I need the styles on all the pages.


href="@routes.Assets.at("bootstrap/css/bootstrap.min.css")" rel="stylesheet" media="screen">
<script src="@routes.Assets.at("bootstrap/js/bootstrap.min.js")" type="text/javascript" />

After adding I refreshed my page and it was getting rendered as blank. None of the contents were getting displayed on the page though I could see them using view source. 

I started playing around and replaced the "/>" with proper ending tag. i.e.

<link href="@routes.Assets.at("bootstrap/css/bootstrap.min.css")" rel="stylesheet" media="screen">

<script src="@routes.Assets.at("bootstrap/js/bootstrap.min.js")" type="text/javascript"></script>

Everything started working as expected. So not sure why it did not work without proper end tag. I will debug the playframwork code soon when I will have some time.

Cheers!
Manisha