Play Framework: Views

home

From working on the Avaje EBean model development and the REST routing, I have not found much to dislike about Play framework development apart from the default settings to lazy load the models when getter/setter methods are not present.

Inflexible Views
My problem with the Play framework is that the template files seem to lack the ability to flexibly pass variables to the view. It is not too hard to add a new field to one scala.html file, but this presents a problem when I edit a scala template such as the main.scala.html. Each scala.html file that calls my main.scala.html file now needs to be modified.

Some assumptions were incorrectly made
During the creation of my models and the related tests, I made some assumptions that were absolutely wrong for request processing. For example, I would create a book instance when an ISBN 13 parameter is found when parsing a form request.

Another assumption I had made was the requests and offers would show everything available rather those a student should view. An example would be I do not need to see another student’s requests, just my own.

Problem: Selenium compatibility with Firefox 20
I have known about selenium for quite some time, but I have always steered away from it due to the complexity. My tests for Fluentlenium failed, because the driver wasn’t able to install on my system with and without administrator privileges. I am running Windows 8 with standard installation of Firefox 20.0.1. A quick search on Google shows that multiple people have this problem. It seems to a combination of the versions for Firefox and Selenium which solves the problem.

Excerpt of the error:

org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127
.0.0.1 on port 7055 after 45000 ms. Firefox console output:
*** LOG addons.manager: Application has been upgraded
...

Solution: Selenium compatibility problem with Firefox 20
If the latest version of Selenium is added to the Build.scala file, then the integration tests will work.

import sbt._
import Keys._
import play.Project._

object ApplicationBuild extends Build {

  val appName = "textbookexchange"
  val appVersion = "1.0-SNAPSHOT"

  val appDependencies = Seq(
    // Add your project dependencies here,
    javaCore,
    javaJdbc,
    javaEbean,
    "org.seleniumhq.selenium" % "selenium-java" % "2.32.0"
  )

    
    // Only compile the bootstrap bootstrap.less file and any other *.less file in the stylesheets directory 
    def customLessEntryPoints(base: File): PathFinder = ( 
      (base / "app" / "assets" / "stylesheets" / "bootstrap" ** "bootstrap.less") +++
      (base / "app" / "assets" / "stylesheets" / "bootstrap" ** "responsive.less") +++ 
      (base / "app" / "assets" / "stylesheets" * "*.less")
    )
    
  val main = play.Project(appName, appVersion, appDependencies).settings(      
      lessEntryPoints <<= baseDirectory(customLessEntryPoints)
  )

}

Project Status
All I finished so far is being able to create a request for each student. If a request is made and a book does not exists in the database, the user will be able to create a record for the book then resubmit the request.

Also, I added a simple login form that will suffice for development purposes only.

requests

request-dialog

book-dialog

Todo List
Finish the offer search,
Add the interested offers sidebar for comparison,
Finish login table with encryption,
Add account creation,
Add password reset,
Add offer creation dialog

offers

Conclusion
Learning the Play Framework was a neat experience. I had some trouble jumping back and forth between HttpServlet/JSP stack and Play due to the different naming conventions. Especially, the way the Java models are saved and found using persistence rather than result sets. I still dislike the method naming conventions, since many of them do not follow Java’s verb naming convention.

I really dislike Selenium for testing. Not because it is a bad testing API, but due to its reliance on a driver to each browser. Basically, the driver must be updated whenever a browser’s plugin api or even the installation directory changes. With the amount of browsers that exists and the volatility of each configuration, I have real concerns about its sustainability.