technologist, entrepreneur, vision­ary, programmer

May 8, 2013
by poornerd

How to Edit Messages in the Browser While Developing Play! Framework Templates

As a followup to my recent experiments to inline editing of content blocks while developing Play! Framework templates, I decided to focus on Messages this week.  Messages are basically Resource Bundles with Texts to be used in the Application.

This is what I wanted to accomplish:

  1. No changes required to the Play! Framework Scala Templates
  2. Use an inline HTML5 editor to edit the messages directly in the rendered template in the browser
  3. Save (update) the message file directly in the conf directory of the application

I modified my play-aloha project on github (https://github.com/poornerd/play-aloha ) for the first requirement, by adding a Messages template, so that the typical @Messages("label.title") tags used in the templates would be rendered by my tag instead.  If the play-aloha.admin=true is set in the application.conf, then the Messages.scala.html template renders a <span> around the message with an id that contains "message." + the key of the message.

@if(Application.isAlohaOn()) {
  <span id="message.@key" class="editable">
@if(Application.isAlohaOn()) {

I also added the class="editable" so that the Aloha Editor which I already integrated into the project would automatically make the <span> editable.

So for example this code in the template would make the messages with the given keys editable:

<h2 class="featurette-heading">
  <span class="muted">@Messages("label.featurette1Mute")</span>



In the controller method which handles saving the edited content from the Aloha Editor via an AJAX Request, I check the id to see if it starts with "message.".

        if (contentId.startsWith("message.")) {
            // save as message
            saveMessages(contentId.substring(8), content);
        } else {
            // save in Template
            if (templateFilename != null) {
                saveToTemplate(fullTemplateFilename, pageId, contentId, content);

If it does, then I use the rest of the id (which is the message) key, to lookup and save the new message in the messages file.

label.featurette1Mute=Google is cool!
If you have read this far, you may as well follow me on Twitter:

May 3, 2013
by poornerd

Wysiwyg Editing of Play! Framework Templates with the Aloha Editor

aloha-savesOk, so it is only partial editing, but still this is an interesting step in the “no CMS” direction. What I have done is modified the example code which I posted on github last week for inline editing of HTML5 elements with the Aloha WYSIWYG Editor to actually save the new content back in to the Scala Template.

I find this useful for allowing non-techie colleagues to edit and optimize text and wordings in more content oriented templates. Of course it does directly modify the source, so in the case of a live website you would want to do this in the development environment and then commit, push, deploy the new version – hence “no CMS“.

In my example I have limited the frontend code to a block in the footer template. It is only rendered into the page if the following value is set to true in the application.conf:


One of the non-elegant parts of the code is deciding which template file to look for the HTML to replace. Right now it is hard coded. I supposed the most pragmatic way would be to create a hashtable mapping URL’s to filenames.

Here you can see the changed HTML in the scala template:



The code is in github here: https://github.com/poornerd/play-aloha

If you have read this far, you may as well follow me on Twitter:

April 26, 2013
by poornerd

How to integrate the Aloha Wysiwyg Editor with Play! Framework

UPDATE: code checked in on github: https://github.com/poornerd/play-aloha

play-alohaI am constantly needing to update static content in Templates in my Play! Framework project, so I decided to integrate the Aloha Editor, an HTML5 WYSIWYG Editor.

It is free to use, and they offer an example of integration an saving with a POST to the server on this page: http://www.aloha-editor.org/howto-store-data-with-aloha-editor-ajax.php

Basically all I had to do in the frontend was integrate the editor as described, and add a class “editable” to the element that should be editable.

<h1 class="editable" id="c1title">Example headline.</h1>

Then I had to create a POST action in my controller:

public static Result aloha() {
   final Map<String, String[]> values = request().body().asFormUrlEncoded();
   final String content = values.get("content")[0];
   final String contentId = values.get("contentId")[0];
   final String pageId = values.get("pageId")[0];
   System.out.println("pageId:" + pageId);
   System.out.println("contentId:" + contentId);
   System.out.println("Content:" + content);
   // save the content or whatever here...
   return ok();

Then I modified the aloha-save.js from the Aloha Example (which I copied from the above mentioned website), to post to the route for my action instead of save.php.

That was pretty much it. Make sure you add an id to the HTML elements so you can tell which on is which. The pageId ends up being the URL of the page, so that is not always helpful.

If you want to find out what I am doing with this, keep tuned to this blog or follow me on twitter!

If you have read this far, you may as well follow me on Twitter:

April 19, 2013
by poornerd

CRUD for Play! Framework 2

Update: yes, those are questions interspersed in the article… please answer in the comments!
crudOne of the main things I missed from Play 1.x is the CRUD Module. After reading posts on the forum about that one or more are in the works, I decided to check them out today.

I found a few projects – all which have key differences:

Am I missing any projects? Let me know in the comments…

Right now I like how easy it is to get fully automatic CRUD Screens using “play2-crud” from njin, but I wish that I was able to build on that more like in the CRUD Module from Play 1.x.

The other “play2-crud” from Hakan Dilek on the other hand has a good basis for writing your own CRUD screens and DAOs, but for a quick start it requires too much coding.

Which of these – from a generic perspective – is the best? Why? Let me know in the comments…

My wish list:

  • Parameterizeable (is that a word) Templates/Tags for the various screens (Search Form, List, Edit, View) which default to the standard view, but where you can specify which fields or columns to show.  These could be included in existing templates.
  • Bootstrap integration with the ability to use the projects Bootstrap / Theme for the automatic screens, as well as turn on/off Bootstrap.
  • Tools for “reverse database generation” of Beans (Ebeans, JPA, etc.)
  • Optional JSON interfaces, with Swagger
  • Optional Security with ?? and Deadbolt

What features do you want? Let me know in the comments…

Maybe it is time to join forces and work on CRUD module that many would find useful and use.

If you have read this far, you may as well follow me on Twitter:

April 8, 2013
by poornerd

How deploy Play! Framework Apps with different configurations to Cloudbees

cloudbees-playHave you ever wanted to deploy the same Application with multiple configurations to Cloudbees, without changing your environment variables each time while using the command line?

I spent a ton of time trying to figure it out, and it ended up being a punctuation problem.

So basically, this is it:

However, if you want to script it, like I did, you want to be able to start the deployment process from the shell as well.

The documentation said:
Deploy a configuration of your app to a Run@Cloud app id. Arguments are:
(1) the base name of a conf file in your project's conf directory, defaulting to "application"/
(2) Optional. The application id to which this configuration should deploy. You can omit this
arg if you have either set cloudbees.applicationId in the config file from the first
arg or have set the project ID in your PlayProject.
Example usage: `> cloudbees-deploy-config live`, where live.conf exists in the project's conf/
directory and contains a key cloudbees.applicationId.

So I tried: play cloudbees-deploy-config xxxxx

That did not work – I got an error like this:
[success] Total time: 110 s, completed Mar 15, 2013 9:08:36 PM
[error] Not a valid command: xxxxx (similar: run)
[error] Expected '/'
[error] Expected ':'
[error] Not a valid key: xxxxx (similar: run)
[error] xxxxx

Thanks to help on stackoverflow, I discovered that it was just missing quotes!

play "cloudbees-deploy-config xxxxx"

Here is the link to the Stackoverflow thread if you want more details:  http://stackoverflow.com/questions/15441628/how-can-i-specify-which-application-conf-to-user-when-deploying-on-cloudbees

If you have read this far, you may as well follow me on Twitter:

March 27, 2013
by poornerd

How to quickly start a Play! Framework Project and Deploy it in the Cloud

playstartjavaJumpstart your Play! Framework 2.1 Java project, by checking out my project scaffold from GitHub: https://github.com/poornerd/playstartjava

Demo running @cloudbees : http://playstartjava.poornerd.cloudbees.net/

The Project Includes:

Follow the instructions on the Cloudbees link after you signup and install the Cloudbees SDK and then just do this to deploy:
play cloudbees-deploy

Thanks to @jaliss for all his help with SecureSocial, and @_JamesWard for adding some libs to WebJars for me!

If you have read this far, you may as well follow me on Twitter:

March 5, 2013
by poornerd
1 Comment

How to switch back and forth between Play! Framework Versions

When I first read about the Play Version Manager I first thought it was some sort of tool for versioning.

When Play! Framework 2.1.0 came out, I finally realized that it was a tool for switching back and forth between various Play! Framework versions.

So download the Play Version Manager from github: https://github.com/kaiinkinen/pvm

You can do things like “pvm use 2.1.0” or “pvm use 2.0.4“.

Here are some of the supported commands:

$ pvm [tab][tab]
alias          copy-packages  help           
list           run            uninstall      
version        clear-cache    deactivate     
install        ls             unalias        

So, download it, and give it a try.

If you have read this far, you may as well follow me on Twitter:

March 1, 2013
by poornerd

Our Energy Saving Server Farm

Ok, so 3 VMWare ESXi Servers running 20-30 Virtual Machines only slightly qualifies as a “Server Farm”, but we will be saving a ton of electricity (sorry Stadtwerke München ) at SiteForce.

IMG_8056Our new setup:

  • 3 Mac Mini Server 2,0 GHz Quad Core with 16 GB each running VMWare ESXi 5.0 which peak at just over 60 Watt each (max 180 Watt) – all the old servers, including mail have been moved to virtual machines, except the Open Directory which is on a QNAP NAS Server
  • 2 QNAP NAS Servers (with iSCSI for VMWare) at about 45 Watt each  (second one is used for redundancy and backups)
  • Telephone System will be virtualized with Sipgate
  • 2 low-power, fanless Cisco Switches ( < 40 Watt each)
  • new Firewall Appliance (< 50 Watt)
  • 1 KVM
  • 1 older Mac Mini as a Backup Server
  • NO MORE air conditioning

IMG_8057We are moving from:

  • 2 x VMWare ESXi Servers which are Dual Quad Core XEON (2,2 GHz) with 24 GB RAM, and dual power supplies which peak at 650 Watt each (that is 4 power supplies x 650 Watt!!!)
  • Mac Pro Dual G5 – with Open Directory and our Mail Server (now on a virtual machine) – with (I am guessing) 450+ Watt 
  • Firewall – old PC with 400 Watt 
  • 2 x Quantum Snap Server ( 2 x 400+ Watt)
  • QNAP NAS (50 Watt)
  • Air Conditioner (300-500 Watt)
  • 2 x 5+ year old rack mount switches (200 Watt ?)
  • 2 x old PC’s as Servers (2 x 300 Watt?)
  • Siemens HiCom Telephone System ( 200 Watt?)

Of course we needed that air conditioning to keep the temp down in the room with all that equipment, and I am sure that some of it is energy efficient and did not always draw full power, but it is safe to say that we had anywhere from 3000-6000 Watt when you add the KVM and Monitor in the rack!

Aside from a few annoying hums from the QNAP NAS Servers, it could almost sit on the desk next to me.  Now we are talking something along the lines of 300-475 Watt!!!

That is a HUGE difference.  I realize that this is not a very scientific or accurate calculation, but the savings are obvious.

We have a little less CPU Power, but we were already overpowered for our necessary virtual machines, and if we need more CPU for a project now, we just go cloud.

If you want to know more about our MacMini Server VMWare ESXi setup with iSCSI then stay tuned, I’ll write that up one of these days, too.

If you have read this far, you may as well follow me on Twitter:

February 10, 2013
by poornerd

Authenticating an Play! Framework Application via Oauth2 and Instagram using Secure Social

Screen Shot 2013-02-10 at 23.33.09In an ongoing quest to make sure that I can easily start a Play! Framework 2.0 project and connect with another popular Social Website via their API, I have just created an Instagram Provider for the Secure Social plugin for Play! Framework.   And it just works….

Many Thanks to Jorge (@jaliss) and his work on Secure Social: http://securesocial.ws/ – he has now added my XING and Foursquare Providers to the master branch – they should be in on the next release!

The pull request is in github here: https://github.com/jaliss/securesocial/pull/149

If you have read this far, you may as well follow me on Twitter:

February 7, 2013
by poornerd

My Upgrade from Play! Framework 2.0.4 to 2.1.0 went smooth except for these few things

Today I decided to upgrade from Play Framework 2.0.4 to the newly released 2.1.0.

I followed their helpful guide: http://www.playframework.com/documentation/2.1.0/Migration

Here is a list of the problems I had, and how I solved them:

  1. When it says change the import in the Build.scala to 
    import play.Project._

    Don’t forget the “play.

  2. It says that “the mainLang parameter for the project is not required anymore” – but it really means remove it.
  3. I also had to Google to figure how to update this dependency:
    "com.typesafe" %% "play-plugins-mailer" % "2.1-RC2"
  4. I also ended up having to update the dependencies for Deadbolt as well to the following:
    "be.objectify" %% "deadbolt-core" % "2.1-SNAPSHOT",
    "be.objectify" %% "deadbolt-java" % "2.1-SNAPSHOT",

Otherwise, follow the instructions – the rest was pretty straight forward.

I also used a pull request from the PVM (Play Version Manager) to download and switch Play Framework Versions.

If you have read this far, you may as well follow me on Twitter: