Play Framework JavascriptRouter Connecting to a Java Controller

Just wanted to go over some of the basics of making use of the

javascriptrouter javascript routing capability in the Play Framework

.  I won’t go in to any major detail but instead will give examples of the minimal setup in Play necessary to get this working.  With this functionality, you can access back end data through your Java controller from a page without a page refresh.  While there are several ways of doing this, wrapping things with Play provides a simple, consistent path with powerful implications.

First, add a route for javascript routing to use and a route for the method that will be called in the routes file:

GET /assets/js/routes controllers.Application.jsRoutes()

GET /cities/:id controllers.Application.getCities(id: Long)

In this, I am passing a simple integer parameter to the getCities method in my Application controller.

Now, in your template, add this script to expose this route

<script src="@controllers.routes.Application.jsRoutes()" type="text/javascript"></script>

You will probably want to throw this in to your main template. This is the one that holds your basic page layout, headers, footers, standard menu items etc. This way it will be available in all of the other templates that include the main template.

In your controller, set up a method to handle javascript routes and a method corresponding to the getCities(int) call

public Result getCities(Long id) {
System.out.println("in getCities in the Application controller");
System.out.println("The id passed in is " + Long.toString(id));
return ok();

public Result jsRoutes()
return ok(Routes.javascriptRouter("appRoutes", //appRoutes will be the JS object available in our view

I’m not doing anything here or passing anything back. Once you have this working, it is up to you what you want to return to the call from javascript. This method simply displays the id passed in to show that it is being called.

Finally, in the template you wish to fetch data for, add the code to make your call through the router from javascript. In this example I am simply passing in a parameter of 1 and showing the returned string data in an alert box. In the provided java method, nothing is returned. You will want to do something real in your method and pass back something useful.

appRoutes.controllers.Application.getCities(1).ajax({success : function(data) {alert(data);});

A reworked and more useful example of the controller method here sends back a set of json formated key value pairs.

public Result getCities(Long id) {
Map cities = City.options(id);
Gson gson = new GsonBuilder().create();
String json = gson.toJson(cities);
return ok(json);

That’s all there is to it! Now that you have the page talking to the controller, you can do most anything you might normally handle with a submit and page refresh without sending back a whole page. For example, as I may be preparing to in this case, load up a list of cities in a dropdown based on a selected state (onchange event) in another dropdown. The documentation I’ve seen on this is mostly geared towards those writing their controller in Scala too. Play has very good support for Java and will hopefully continue to allow both Java and Scala controllers in the future. It is currently my favorite way of putting Java to use on the web. If the 3.x versions of Play become even more Scalified, that is, the option of writing model and controller code in Java rather than Scala goes away, I will abandon Play and try something else. Basically I am saying, if I have to program everything in Scala, I would just as soon make the move to NodeJS. I am using Play specifically because of the cool way it handles routing web requests to Java code. The Scala you have to use in templating is fairly simple. I’ve even developed a few little Scala tricks I’ve become fond of in my template code. However, I’m not at all interested in developing complex application logic in Scala or javascript for that matter. Scratch the NodeJS comment. I’ll just skip the framework all together and create REST stuff by hand. For now though, the Play framework has been a great addition to my web application strategy. This javascript routing stuff is an example of just how slick it is as a framework for modern web applications.

For more information, check out this article which goes in to a little more detail on javascriptrouters in play with java controller code


Donald Trump on Jimmy Kimmel Don’t Be A Loser

I’ve been following the presidential race fairly closely and it looks like we may just get a president that doesn’t suck this time. Check out this poem from the Donald Trump interview on Jimmy Kimmel last night. This is funny as hell.

Winners aren’t losers. They’re winners like me.
A loser’s a loser. Which one will you be?
Winners do deals and winners get rich.
While sad little losers just sit there and bitch.
This lobster’s a loser. Throw him in the pot.
I like a lobster who doesn’t get caught.
Now, here are some frogs I do not like at all.
We must kick these frogs out and then build a wall.
Oh the places you’ll go, on your yacht and your plane.
With your suits from Milan and your wives from Ukraine.
Oh the buildings you’ll build, oh the wealth you’ll amass.
Oh the people around you all kissing your ass.
There are two kinds of people. Which one will you be?
A loser like them, or a winner like me?

Do I think he will be an effective president? Yes I do. We really need this. It is hard to believe I am living in a country that might choose a candidate like Hillary Clinton over someone like Trump. We have to get out there and prevent this. If not for any other reason, do it for the entertainment value.

Trouble With Your BlueTooth Speaker in Ubuntu 14.04 LTS

When I first got my portable bluetooth speaker, the Sony SRS X-5 (pictured on the left) it’s connection to Ubuntu was fairly automatic, as it should be. I would push the bluetooth discover button on the top of the unit, Ubuntu would see it and pair without much trouble. At some point a few months ago, this stopped working as it had. I could still get it to connect but it took a lot of playing around, removing it and adding it back, before I would actually get it working and set up A2D2(high fidelity playback). Not sure what was actually going on but I found out how to fix it. If you are using Ubuntu 14.04 or Mint Linux or similar, simply turning bluetooth on and off and similarly cycling your speaker’s bluetooth will no longer work. What does is the following. First, open a terminal window (ctrl-alt-t) and enter this at the command prompt:

sudo pactl load-module module-bluetooth-discover

Enter your password if prompted. Your linux bluetooth module should now be restarted. Open sound settings, push whatever button you have to on your device to search for a connection, and your bluetooth speaker should now show up in your list of output devices. You will likely have a combo box with a couple of choices of modes. Select “High Fidelity”(A2D2) and test it out. If you are still in telephony mode, or for whatever reason something is not right, you may not see left and right options to test. In this case, click on the bluetooth icon in your menu bar and select devices. If you don’t have a devices option, install the bluetooth device manager. You can find this in the Ubuntu Software Center or apt-get it. If you see you your speaker in the device manager, remove it and then add it back. This should work just fine but will not usually unless you have reloaded the whole module as instructed above. Now you should be able to go back to sound settings and configure your speaker for A2D2 High Fidelity output in stereo. Test it all out and set your volume. You are ready to go! Hope this helps.

On a side note, I would like to mention that I really do love the SRS X-5. The Bose mini, pictured on the right, doesn’t even come close. It is strange to me that they get compared so often. I guess this is because they are in the same price range. In terms of audio performance, the Sony beats the Bose by a wide margin.
I am normally critical of Bose bass capability. It sounds, for lack of a better word, “flappy” to me across their entire range of products. I am not sure why this is, and of course I can not argue that their speakers do perform a lot better on average than many of their competitors, however, in this particular case, the Sony is the clear winner. The SRS x-5 is not a bass monster but does handle most music quite well given its size and price. It is important to keep it plugged in as when running on battery, the woofer output is cut in half. It’s bass is more of a mid-bass and it shines in the case of music that is most dependent upon this range and up. If you listen to hip hop or the like and enjoy your music loud, this speaker will not make you happy. Nor should the Bose for that matter, yet many such listeners will probably side with it for name alone. For my tastes, I am very impressed with the x-5’s performance when compared against other sub-200$ bluetooth competitors. While portable, this is not a take anywhere speaker. So, if you are headed to the beach to jam out, you may want to choose something else. For moderate volume, at home listening, or in my case, something to have with you in the hotel room when travelling for work, the Sony does a great job making up for that stereo you miss. I even found it’s audio enhancement mode, a concept I would normally skip with most products, actually does sound good and effectively improve the device’s sound stage. If you don’t already have several of these gadgets, now that you have your Ubuntu bluetooth speaker connectivity issue resolved, I would suggest grabbing one of these. It is well worth the retail, but if you wait a little, you may find it refurbished on Woot! for 80-90$ as I’ve seen it lately.

The Web and the Decline of the Middle Man

At one time, it was pretty standard for a real estate agent to be involved with every sale of real property in the US.  When the market boomed a few years back, more people than ever jumped in to grab their share of this easy money.  You can’t sell your house, building or lot without an agent and when it sells, that agent is entitled to 6-10% of the sale price.  How did this system evolve?  Is selling your property really that complicated as to require a consultant who ends up “earning” 10k, 20k, 50k or more.  How much could this person actually be worth when to become an agent all that is required is reading one little book or taking a short course over a few weekends and then passing a basic competency exam?  Apparently the public has finally given these questions the attention they deserve and the market has changed.  For decades, the real estate business has thrived based on it’s control of information.  While most of the actual complexity of handling a real estate transaction is dealt with by a lawyer, the brokers and agents have maintained their position in this deal by the guarding their information.  In every state, an agency would maintain a book containing property listings, the MLS.  This book was only available to licensed brokers.  Furthermore, rules and regulations were lobbied in to place by this and other agent supported associations to secure their role in property transactions with the argument that they somehow protected the consumer.  While not all of reasons agents and their strict code of ethics were imposed upon this market were bad, the price paid for such services and protection was clearly outlandish.  Now, access to lists of property for sale are easy to come by, thanks to the internet.  So is information on how to manage a real estate transaction.  The real estate industry now finds itself on shaky ground and commissions have fallen drastically.

The same has happened in the car business.  Web sites such as truecar are working to provide consumers with the information they need to make better buying choices.  The car salesman used to play an important role in the typical new or used car purchase.  Now, anyone with the internet can walk in to this type of transaction knowing almost everything needed to make a good choice without the help of a highly paid car consultant.

Quite a few other industries are experiencing similar evolutions.  Almost any job with the title of agent, salesman or broker is either going away or adapting to much higher expectations and lower margins.  Some are going away all together.  When was the last time you called your stock broker?  Personally I think this is great.  Not only am I fond of economic efficiency and perfecting markets, but in times like these, it is becoming critical for the nations economic survival.

In all of this, one would expect the business of staffing, recruitment, job placement to be dwindling to nothing.  Of all of the “agent” style businesses, this is arguably the most questionable in terms of value to the consumer.  How does someone secure an income of 100k, 200k or more simply by running a few searches and making a few calls?  Why has internet availability of information on the job market not totally eradicated this line of work?  Clearly this industry is hanging on some how as year after year tech search firms, staffing firms and the like report 10s of millions in revenue with no end in site.  The current job market is arguably in worse shape than the housing market.  Why does this tax on employment still exist at all?  Are recruiters providing value that other agents and brokers in other industries were not?  Either the answer to this question is yes, or something else, something far less palatable, far less redeeming, far less defendable is happening.

In Play Problem with MariaDB JDBC Driver Client org.mariadb.jdbc.Driver

My latest Play problem was actually a jdbc driver bug.

With all the fixing (and learning) I’ve been doing the last few days trying to get the hang of ebeans in Play 2.4.x, the last thing I expected was one of my biggest hangups to be a jdbc bug.  As anyone who has been here knows, I am a huge fan of MariaDB so don’t take this to mean otherwise.  However, if using the Maria client 1.3.2 in Play with ebeans or likely with many other common ORM’s, and you get an error like:

[PersistenceException: ERROR executing DML bindLog[] error[getGeneratedKeys error. Statement.RETURN_GENERATED_KEYS must be precised on connection.prepareStatement(String sql, int autoGeneratedKeys) or statement.executeUpdate(String sql, int autoGeneratedKeys)]]

It isn’t you. It is actually a bug. A smart guy timowest pointed this out on github 10 days ago

Looks like a bug in the driver

The flag Statement.RETURN_GENERATED_KEYS is missing.

I switched to the oracle driver in application.conf and all works great.  Good find Tim!  I’ll be switching back as soon as this is resolved in the maria client binary.  I’m hoping this has been reported.

While I’m giving a shout out.  Thanks also to Matthieu Guillermin and his great post on getting around ebean optimistic locking in Play.  You can find his great post here


Play 2 Framework Pagination Stuff Has Changed Version 2.3.7 to 2.4.1

If you are trying to get the computer database example in Play 2 to work which is in 2.3.7 and you are using version 2.4.1 or later, you will find that there are some minor changes to the pagination code.  Here is how to get Play 2 Framework Pagination working.


The original code will look something like this:

public static Page page(int page, int pageSize, String sortBy, String order, String filter) {
.ilike("name", "%" + filter + "%")
.orderBy(sortBy + " " + order)

Upon you compiling, you will find that FindPagingList is now gone.  Use findPagedList(int,int) instead.  Here is an example that works for  a different table.  Just replace “alias” with “name” and change the fetch to “company” and things should be back working in version 2.4.1

public static PagedList page(int page, int pageSize, String sortBy, String order, String filter) {
.ilike("alias", "%" + filter + "%")
.orderBy(sortBy + " " + order)
.findPagedList(page, pageSize);

You will need to import the com.avaje.ebean stuff too.

import com.avaje.ebean.Model;
import com.avaje.ebean.PagedList;

Finally, don’t forget to change your views to use com.avaje.ebean.PagedList too.

The Rich Recruiter? Things Have Gone Terribly Wrong!

I just ran across this book out on Amazon Unlimited.

The Rich Recruiter

When you check it out, you will also find lots of other books on how to get rich in the placement business.  In particular, this occupation has risen up take its share of the money being thrown around in the information technology field.  What money?  Exactly.  Back in the late nineties, lots of things emerged from the shortage of IT guys most companies were facing.  The web was taking off, the Y2K disaster was looming and the nasdaq was soaring.  There just were not enough computer geeks to go around.  In response, lots of barriers to foreign workers were brought down, contracting rates went through the roof and the staffing business grew in to a monster.  Of course, like all bubbles, this one burst.  Nothing much came of Y2K, all of the workers brought in to fill IT positions stayed on to depress contracting rates and we have more people out there than ever looking to get rich off  of the poor, socially inept, cubical dwelling computer guy.  IT wages are not nearly what they were 15 years ago though.  In 1998, it was nothing for a database programmer to make $150/hr.  Just for locating one, a recruiter could often charge another 25-50$ on top of that.  Well, times have changed, yet the recruiter has stayed on.  It’s a lot harder to get rich in the placement game than it used to be, but, as this book describes, if you are persistent in your efforts to wedge yourself in between employers and employees, you can still extract quite a hefty economic inefficiency for yourself in today’s market.  As a developer, you are likely familiar with how this business effects our business.  Say you are finishing up a contract and would like another one.  It would seem reasonable that you would put your resume out for potential employers to see.  You might even look for a job listing and submit your paper via email.  But wait…the listings you see are not for jobs, well, at least not directly.  They are recruiters.  They may have a job in mind, or they may just be trying to build up their list of contacts.  They live and die by this database of people that can actually do work.  Matching on keywords that they really do not understand or even much care to, they laboriously filter and sort resumes against listings looking for opportunities.  When a match is found, they call the developer, call the employer, arrange a meeting and then, if all goes well and employment results, they sit back and collect 20k, 30k, maybe even 50k each year that the employment lasts.  Yes, you can still get rich in the recruitment game.  Very rich in fact.  While not as lucrative as in the past, the big players still report 10’s of millions in annual income, all based on matching people to jobs.  My question is, given that wages are no longer inflated and the market is no longer experiencing a shortage of workers, do we still need to be bringing in new people from other countries to fill our tech jobs?  Marco Rubio thinks so.  He believes the number of h1visas approved each year should be increased 4 times to somewhere around 240 thousand a year.  What will this do to the wages of American citizens who work in IT?  Will it make them go up?  Seriously, Rubio is running for president.  Who is he planning on working for?  Why would I vote for anyone who wants to use the Presidency to depress American wages further?  And while information technology wages are 1/2 to 1/3 of their past glory, have staffing company margins declined likewise?  Even if the answer is yes, should there even be any margin in the first place?  Recently, a job for a MongoDB dev/admin position opened up some where in Georgia.  Within 2 days, I had been contacted by no less than 10 different recruiters, all with very personal form letters, none residing in Georgia themselves (mostly New Jersey residents), asking me if I would be interested in moving 1000 miles to take the position.  Funny thing is, very often the same thing happens when a .NET position opens up in St. Louis.  I am not a .NET programmer.  These guys aren’t even reading the resumes any more.   It is a numbers game for them and that’s about it.  It is actually kindof insulting.  You can press the spam button in gmail but does this really do anything?   For fun, call them all back.  One will insist that he can offer no more than 60/hr while another will offer 70 right off the bat.  You are not negotiating with a potential employer, you are negotiating with a person who has imposed himself between you and the employer and he/she is deciding how much they want to make next year off of your labor.  Whether it be 10k, 20k or 30k, I believe it is 100% too much.  What does that come out to by the time you have moved in to your Atlanta based cubicle?  5 thousand dollars a phone call?  100 bucks per spoken word?  Are you really so frightened by the job search process that you are willing to give up half your pay next year to have someone hold your hand?  Is getting a job in a field you know really such a revolutionary idea that you should pay someone 10’s of thousands of dollars for suggesting it?  No, No, NO!  If I want to move to Georgia to work on a Mongo database, I will look for the employer myself and split the difference with them.  In today’s economy, that is how we should all do things.  After all, isn’t this the way other jobs work?  So how do we fix this?  You really should not be able to Get Rich recruiting in today’s economy.  Actually, the solution is simple.  Managers, do your jobs.  When you need an employee, post the position.  Add the line “Please No Recruiters, Only Applicants” to the bottom of your listing.  When responding to ads for employment, do your best to only respond to those from real employers.  Keep your spam folder empty and don’t make the mistake of posting your resume out there on the boards.  If you do, add the same type of line to it.  And be adamant about this policy.  You do not, i repeat :), You do not need to pay someone 30k a year for the opportunity to make 100k a year doing your job.  Job boards, clean up your act too.  I know you get paid for listings, but isn’t the quality of the listing part of your value proposition?

Anyone else out there tired of giving away half their pay check?  Employers, doesn’t it make you ill having to pay 2 people for every 1 programmer you hire?  It is high time we put an end to all of this.

Amaya HTML Editor Won’t Start in Linux

You may have an interest in using Amaya in Ubuntu, Mint or other Linux distribution of your choice and be having trouble getting the application to stay open.  While a lot of web developers use Linux, editor choices are fairly slim out there for those looking for wysiwyg or partial wysiwyg support.  For a decent list of what is out there click here: 20 Best Free HTML Editors for Linux and UNIX  While it’s been a few years since it was updated, the one which I was most interested in using was W3C’s editor Amaya due to it’s support of html5 and it’s by default industry standard position.  The Linux version for a lot of you will appear broken right out of the box.  Particularly, if you have intel integrated graphics and are depending upon Mesa, Amaya will crash shortly after opening, often with little warning as to what happened.  In Windows, Amaya depends upon hardware OpenGL stuff.  If you experience crashing or slow performance, the Amaya site recommends updating these drivers from your graphics chip manufacturer.  Linux implementations, however, use software drivers.  While I’ve not had trouble on systems with dedicated graphics like my box with a gtx770 card, the mesa drivers on my laptop with integrated Intel Iris drivers seems to throw Amaya for a loop.  To get the application running, try this trick.  Create a shortcut to Amaya on your desktop or task bar.  In the shortcut, place this text in the command “amaya %u index.html”.  Make sure the reference to Amaya is pathed correctly and that the page being opened initially (index.html) is something you would like to start with and is accessible.  I use a boilerplate template as a start.  Apparently, starting Amaya without an initial page selection causes an exception of some sort.  Try things this way and you should at least get the application to stay open.  How it runs after that will depend upon a lot of other things.  It is working fine for me so far.


I hope this gets you going on Amaya.  Here is a product I just got started with that you might find even more helpful.  So far seems much less buggy in Linux.  Also, appears very up to date and powerful.  It uses Gecko for rendering.  No problems yet.  Give it a try!

Download BlueGriffon