Play Framework 2.0 Java Controller Route Sub-Packages/Folders


The Play Framework is an awesome change from JavaEE. I like how they embrace Object Oriented design throughout the framework. The Play Framework is Java’s version of Django or Ruby on Rails. By default, it uses EBean as the ORM and it has been a refreshing change from Hibernate as well. It is the the most rapid web development framework that I have used in Java. I came across my first curve-ball with it that was not easy to find when googling it.

I don’t like flat project structures. I always plan that even the smallest projects will have a ton of models, controllers, and views and they should all be segregated in their own folders/packages. I placed my logged-in controllers in their own package in controllers.tracker.*. The trick was to get the routes object to work.

I assumed that routes.tracker.DashboardController.index() would work, nope. Apparently there is a routes object at each level of the package structure under the controllers package. So here’s what worked:

    return redirect(controllers.tracker.routes.DashboardController.index());
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s