IntelliJ IDEA - Multiple DB Consoles (And Recovering Ones You Didn't Intend To Close)

I use the Database view/plugin in InelliJ IDEA quite often.  It’s actually become my “go to” editor for SQL scripts because of it’s responsiveness, the fact that it’s right there inside my IDE and the code completion and join hints are often times better than the DBMS vendor’s offering.  It’s pretty easy to open a new console to start writing queries once you’ve set up a datasource.  You can click the ‘SQL Console’ icon in the toolbar, or right click on the datasource and choose ‘Console’:\

Spark Java "Flash" Scope

One of the handiest features of Grails is the “flash” scope.  The flash scope is “A temporary storage map that stores objects within the session for the next request and the next request only, automatically clearing out the objects held there after the next request completes.”  It’s a handy way to send messages and errors around when dealing with form posts and redirects.  Since I’ve been working with Spark Java I’ve found myself missing this little feature so I decided to throw together my own implementation.  I’ve added the following closure inside of my main() method in my Bootstrap class:

Realtime GPIO On Raspberry Pi With Spark Java And WebSockets

I’ve blogged in the past about using Spark Java to get a simple website running on the Raspberry Pi.  In this demo I’ll do just that and in addition I’ll implement a simple GPIO handler to listen for a button press event.  When the event handler fires, I’ll turn on an LED and broadcast a message to subscribed websocket clients to tell them about the message.

JavaLite ActiveJDBC For ORM In Spark Java

I’ve spent a lot of time on the blog lately talking about views in Spark Java applications.  Rightfully so, as Views are the Turkey in any MVC sandwich (look at it…it’s right there in the middle!!).  Spark Java provides the crusty Controller slice of bread via routes in our Bootstrap class.  So the only thing left is to take a look at the other slice - the Model.

MongoDB via Morphia in Spark Java

The latest journey in my quest to see just how many new technologies and frameworks I can learn in one week involves Morphia.  Morphia is a “Java Object Document Mapper for MongoDB”.  In other words, it let’s us map our POJOs and POGOs to MongoDB Documents and persist them in MongoDB.  \

Right, so, on to the codes.  To get started with Morphia declare a dependency as such:

compile group: 'org.mongodb.morphia', name: 'morphia', version: '1.3.1'

Obviously you’ll need to make sure you’ve got access to a running instance of MongoDB before you try to connect/persist to it.  Next, create a domain class - we’ll call this one Person:

Spark Java Views With Apache FreeMarker

In the last few posts I took a look at using Thymeleaf for view rendering and templating with Spark Java.  Thymeleaf has it’s advantages and disadvantages, but I could see using it in an application without suffering too much grief and having it actually be enjoyable to work with.  I thought I’d take a look at another option for views in Spark Java:  Apache FreeMarker has been around a looooongggg time - since 1999.  Amazingly, it’s still under active development (the most recent release was 3/2

Spark Java Views Using Thymeleaf - SiteMesh Like Layouts

In the last post we looked at how Thymeleaf handles reusable layouts.  A reddit user enlightened me about an open source ‘dialect’ for Thymeleaf that makes it behave in a similar manner to SiteMesh.  It’s documented pretty well, but...

https://objectstorage.us-ashburn-1.oraclecloud.com/n/idatzojkinhi/b/img.recursive.codes/o/clooney.gif

Yeah, documentation can be boring sometimes, so I thought I’d put together a quick post on how that would look in the Spark Java application I’ve been working with.  It works well, but it suffers from an inability to pass model variables to the layout template.  That’s something that SiteMesh can handle (although in a less-than-elegant manner in my opinion) and in my view it is almost deal breaker.  Something as simple as a nav menu that is common across all pages will ultimately require some dynamic data, and if we’re going to need to th:insert the fragment on every page, then what are we really gaining by using this style of layout template?  I’ll add how I’d think this could be handled at the end of this post, but first let’s look at how to implement this dialect in the project.

Thymeleaf - Passing Variables From Child To Layout

Just a quick update after my last post to clarify things a bit.  I mentioned in that post my dismay regarding the inability to pass model variables from the child view to the parent layout - and I shared that concern with the dialect developer Emanuel on GitHub.  He quickly wrote back to clarify that it is indeed possible:

Hi Todd! First of all, nice blog - I came across it the other day when you wrote about using Thymeleaf w/ Spark \

Spark Java Views Using Thymeleaf

The next step in using Spark Java with Groovy that I would like to look at is getting data into a view.  With Grails, we’re used to using GSP pages - and they work great, but Spark Java doesn’t have view support out of the box.  Instead, it let’s you choose a template engine.  The alternative is to simply serve static HTML pages and retrieve any data via Ajax calls.  That’s a valid strategy in some cases, but most sites will require some level of dynamic data in the view and requiring Ajax for all of that data isn’t always the best solution.  Enter Thymeleaf.  In their words:

Spark Java Views Using Thymeleaf - Layouts

In the last post we looked at plugging in Thymeleaf into a Spark Java application for view rendering.  The concept was pretty simple: using the Thymeleaf engine, render a view with a map of variables to use as the model.  But in reality, our applications need a bit more complexity.  They need reusable layouts.  In this post we’ll take a look at how to handle that with Thymeleaf.  

Reusable layouts include things like headers, footers, scripts and other things like nav menus that are common across the application.  Thymeleaf accommodates these by using what they call “fragments” - reusable blocks of code defined by the th:fragment attribute that can be called from your templates using the th:replace, th:insert or th:include attributes.  You can read all about it in their docs, but let’s take a look at a practical example below.