Wisdom, an awesome java web framework
Few years ago, a friend of mine told me about Play Framework (first version). For me it was a great find, and finally I found the Java web development became âchildishâ and I began to get serious with it (I wasnât a Java developer, but a C# and ASP.Net developer). I loved this framework. Then there was the next version, splendid, but less âchildishâ (I had become a lazy Java developer), so, suddenly, I went to JavaScript (Node, Express, âŠ), except the lack of class, I fell in love with JavaScript. I tried other interesting frameworks as SparkJava, SimpleFramework, ⊠They are very nice and simple but they provide much less âhelpersâ. We can see them as âmicro-frameworksâ and I play a lot with them. But no more âwizardryâ.
Not long ago, an other friend of mine told me about Wisdom and finally, yesterday, I decided to give it a try. And the first few minutes of use, I had this strange feeling that I had found My Framework!
The use I made of this tool (since yesterday, remember) is probably not orthodox, but I hope it will make you want to go deeper.
I know, my English is creepy, but i try to improve it :).
Above all, the installation
You need Java 7+ (Java 8 is also supported \o/
) and a recent version of Maven (3.2.1+). And there is nothing to install because the mvn
command of Wisdom build process will download everything (remember, Iâm a lazy man ;))
So, create a project
Iâm working with OSX and Linux, but you can find more details here (even for Windows developers): http://www.wisdom-framework.org/reference/0.6.1/index.html# _your_first_wisdom_project.
Type this command in a terminal to create a new project:
mvn org.wisdom-framework:wisdom-maven-plugin:0.6.1:create \
-DgroupId=bob \
-DartifactId=bob \
-Dversion=1.0-SNAPSHOT \
-Dpackage=org.k33g.bob
remark: you have to replace bob
and org.k33g.bob
with your own data.
The command geberate a directory (bob
for me) and project, and now you can open it with your preferred IDE.
And launch this to run your application:
cd bob
mvn wisdom:run
Wisdom load all what he needs and then you can open your browser to: http://localhost:9000.
The structure of the project is like that:
Modify WelcomeController
We change only the value of the uri
(from "/"
to "/welcome"
):
Save it, now if you go to http://localhost:9000 youâll get a âNo route foundâ message and you find again the welcome page if you go to http://localhost:9000/welcome.
- Remark : when you call http://localhost:9000/welcome,
welcome()
method ofWelcomeController
is called.
This is the first magic trick!!! Hor reload!, thanks to the watch mode, Wisdom picks up all your code changes immediately! Nice!
Create our own controller and the associated template
I just want a simple html home page. So, create a simple controller IndexController
in /src/main/java/org.k33g.bob
:
- Remark : when you call http://localhost:9000,
index()
method ofIndexController
is called.
Note this, weâve declared a Template
object : index
, then weâve to create a template : index.thl.html
in src/main/resources/templates/
:
- Remark 1: Wisdom uses Thymeleaf Template Engine.
- Remark 2: Wisdom uses WebJars to provide javascript and css frameworks. Regarding to us, jQuery and Bootstrap are already provided, but you can remove dependencies in you pom.xml file.
- Remark 3: Weâll see how not to use WebJars, but later.
When youâve saved your two files, you can just verify that all is OK: just refresh http://localhost:9000. Easy, no!?
Create a Json service
Create a new controller HumansController
in /src/main/java/org.k33g.bob
:
You have to save your java file, and now go to http://localhost:9000/humans with your browser, and youâll get this:
So, you can modify index.thl.htm
:
Iâve only added a list <ul></ul>
ans some JavaScript code to call Json service and populate the list. Just refresh http://localhost:9000:
Fine!
Playing with Wisdom and Polymer
Iâm a big fan of Polymer, but I need all âcore elementsâ and Iâve not found the necessary webjar for them. First, stop your application, we have to modify pom.xml
file, and it requires relaunching the watch mode.
I need Bower to install Polymer and itâs dependencies, so I have to deactivate Google Closure minification (Wisdom automatically minify all javascript files of your project) because Bower load a lot of files and minification is too long.
Deactivate minification
In pom.xml
replace
by
you can delete jQuery webjar dependency too:
And you can restart your project (mvn wisdom:run
)
Install Polymer
Remark: you need Bower then npm then Nodejs.
Inside this directory: src/main/resources/assets/
, create 2 files : .bowerrc
and bower.json
with these contents:
# .bowerrc
# bower.json
And type this command: bower install
. It will create a sub-directory bower_components
with all necessary dependencies to play with Polymer (include jQuery).
First WebComponent
Inside this directory: src/main/resources/assets/
, create a new sub-directory : components
with a new file humans-list.html
with this code:
And go to index.thl.html
again, and modify it like this:
remove <ul></ul>
and replace it with <humans-list></humans-list>
change jQuery reference and add polymer platform reference
add reference to our new WebComponent humans-list
remove jQuery ajax call
Refresh your page:
I think Iâve found THE Best Candidate to serve my Single Page Applications :)
Tweet