By the way, I, like many other people, despise unfounded strong opinions around platforms, frameworks and libraries. That said, here’s mine: If you consider using Subversion on a new project and you have control over which version control software to use, don’t. Just don’t. Use Git.
First, install it, because it has been split of recently from the main grunt project. After successful installation, which you can verify by opening the terminal and typing
I’d love for you to navigate to ~/.grunt-init, or %USERPROFILE%/.grunt-init if you are on Windows, like me. We now want to clone a Git repository from Github, resulting in a folder in this location called standardstack. That name is not well chosen, and I do feel guilty about it. Nevertheless, carry on by now executing the following:
Now create a folder for your new project. I’ve picked this location:
Point a terminal there (cd c:/development/todolist), and simply type:
It will prompt you for a project name and title, and subsequently give you a list of further commands to execute. Execute them one after the other, just as instructed:
npm install bower install grunt
I encourage you to now look inside that project folder and find the awe-inspiring structure there, all set up and welcoming you as its hero who will raise it from its skeletal simplicity into the beast that it will become.
I always cry here. No, be strong. We soldier on.
If we could set up a server and point an alias to the /dist folder there, we could simply add changes to any of our files, and refresh the browser to see the updates. This is made possible by virtue of grunt’s watch task that listens in on changes in the specified folders.
and constantly refresh there after each change is saved in our project. Everything is concatenated, minified and compiled on the go.
Finally, I recommend one more tool - an IDE this time - Brackets. After some terrible sleepless nights, I have come to the point where I can definitely say Eclipse is just a bit too heavy for js development. I mean, I’ve allocated 4GB of juice to it - -Xmx4096m, having 16GB in total available. It doesn’t use all of that, to be fair, but it tries to help so much that it slows me down and I find myself waiting for it to catch up too often. Too often, I tell you. So, Brackets is my new best friend, and I haven’t looked back yet. Well, I have, but only to give Eclipse that look you give an ex.
So now, for those of you who are into that sort of thing, you could download the grunt and git extensions for Brackets, and manage everything inside the IDE. This is not a requirement, but I’ll tell you, I myself have done that, and I am still thrilled to have the grunt tasks listed in a sparkly GUI. It’s just nice.
I recommend the above setup for a broad range of projects. Automation is generally very rewarding. There is a plethora of very practical grunt-init powered setups out there. I challenge you to search grunt-init in GitHub. You’ll soon see what I mean.
This brings us to the end of this post. In the next one, we’ll create the to-do list. Thanks for reading!
In my previous post, we have set up a Wildfly instance to host our REST services. In this post, we
proceed to implement the actual RESTful services for our todo list application.
As a side note, why are we not just using node.js for this back-end? Well, funny you should ask that. The reason is that we are simulating an application that requires mission-critical transactional integrity,
among other standard enterprise features. I do strongly believe in the power of Java EE 7 to deliver all this - it is surprisingly light-weight for this level of robustness and encapsulates all the enterprise
complexity, leaving us to concentrate on the business logic. Also, as a responsible developer, I never create any application escaping the power of our lord, Eric Evans
and his wisdom of the domain-driven application. Therefore, you will notice that I create a couple of classes, probably more than necessary to simply achieve the required functionality, aiming to decouple the
domain from the rest of the application.
But of course, I digress, and I’ll make up for it by presenting our entity:
public class ToDoTask implements Serializable
private static final long serialVersionUID = 7296051067463179978L;
private Long id;
private String title;
private boolean completed;
private Date creationDateTime;
public Long getId()
public void setId(Long id)
this.id = id;
public String getTitle()
public void setTitle(String title)
this.title = title;
public boolean isCompleted()
public void setCompleted(boolean completed)
this.completed = completed;
public Date getCreationDateTime()
public void setCreationDateTime(Date creationDateTime)
this.creationDateTime = creationDateTime;
As you can see, the Wildfly archetype has done the work for us to connect Hibernate with Wildfly’s built-in database, H2. We simply annotate our entity as above
and the corresponding table will be created as soon as we deploy this application.
Next, we want to create a class that will perform the CRUD operations on this entity. For operations that make real changes to our persistence, i.e. the write operations, the CUD part of our CRUD, we need the transactionality,
but we don’t want to write it ourselves. Therefore we opt for a stateless session bean as below:
The first method will handle creating and updating, the second removal.
For the read operation, we create a separate, lighter class that will not employ all the transactionality. However, we still want to be able to inject it effortlessly into other classes,
so we decide on a @ApplicationScoped CDI bean:
Here you’ll notice a bit of cheeky Criteria API bits. We can query our persistence layer within the safety of strongly typed queries. Nice.
Cleverly, as entities are updated in the ToDoTaskManagement class, it fires an event. The following class listens to these events and updates itself by calling an injected reference of ToDoListRepository
to update a cached list of all todo tasks:
You’ll notice we include the standard operations needed for our corresponding Backbone.js model:
@GET for getting the full list (already ordered in descending chronological order by virtue of the query we used earlier) @POST for creating a new task @PUT for updating an existing task @DELETE for copying a task - just joking - are you still awake?
Also note that we use @Produces in this class, but it is not related to the previous one. This one is from Java’s REST library, javax.ws.rs.*.
We deploy the application as described in Part 1 of this series and we are curious whether everything is behaving as we expect.
Of course, this is where SoapUI is a godsend. Create a new project, then a test suite, then a test case, and finally a test step, an HTTP Test Request, to be precise. The endpoint will likely be
And finally we decide this task has been with us long enough, and we get rid of it:
Notice we pass in no json this time, but again have appended the id to the URL:
For our next step we might well decide to run the front-end from a different port - on a different server, even! Therefore, we need to add something that will decorate our responses with the appropriate headers to allow this sort of thing. Let’s
create a filter that we just drop into the ../rest.* package.
Before we can use the javax.servlet.* library, we need to add this as a dependency in todo-web’s pom.xml, because the Maven archetype did not include this for us:
In these dark days, we find ourselves listlessly longing for order. Therefore, let us create an application that brings us a beautiful to-do list. For this exciting prospect, I plan to use the following stack:
Java EE, REST;
Lest we swallow the elephant whole, I’d rather we broke this down into a series of posts. That way, we maintain sanity across the board. In this post I will set up the back-end skeletal framework of the project.
If we are able to see Hello World! on a local running instance of Wildfly, that would signal success, and we then ought to smugly look back and reminisce over our journey. And then move on.
Now, cunningly, when I open Eclipse, we immediately notice that I have the M2Eclipse (Maven) plugin pre-installed.
This would be the case for you too if you chose the Eclipse edition for Java EE developers. However,
if you do find your Eclipse instance is without the joy that Maven brings, you would simply need to add http://download.eclipse.org/technology/m2e/releases to your software update sites and install the software. Information on how
to do this is available here.
I start by following File -> New -> Maven Project, wanting to create a new project from a Maven archetype. To enable this, I need to have added the appropriate catalog for Wildfly archetypes: