This article follows Jspresso in 10 minutes where you have set-up a yet simple but complete Jspresso powered application project. Due to formatting restrictions, lines of code may be cut in pieces. In that case, the end of line is escaped by the "\" character.
The goal is rather simple : develop a CRUD module on a City entity. A city entity has a name (max length 64, mandatory) and a zip code (max length 10).
Download the following PNG icon image
and save it under :
helloworld/core/src/main/resources/com/example/helloworld/images/city-48x48.png
Edit the SJS (Sugar for Jspresso) source file for the model located here:
helloworld/core/src/main/dsl/model.groovy
Copy and paste the following entity definition :
Entity('City', icon:'city-48x48.png') {
string_64 'name', mandatory:true
string_10 'zip'
}
That's all you need to do to describe your entity; Jspresso will do the rest.
Move to the root directory of your project (${WORKSPACE}/helloworld) and type :
mvn compile
The command above has generated and compiled the City entity. If you wish, you might take a look at the following source directories where you will find its java source file and hibernate mapping file.
helloworld/core/target/generated-sources/entitygenerator/com/example/helloworld/model/City.java
helloworld/core/target/generated-resources/xdoclet/com/example/helloworld/model/City.hbm.xml
Download the following PNG icon image
and save it under :
helloworld/core/src/main/resources/com/example/helloworld/images/masterdata-48x48.png
Edit the SJS source file for the front-end located here:
helloworld/core/src/main/dsl/frontend.groovy
Before the controller definition, insert the following workspace definition :
workspace('masterdata.workspace', icon:'masterdata-48x48.png') {
filterModule('masterdata.cities.module', component:'City')
}
Look for the comment "/*Reference your workspaces here.*/" and replace it by the workspace identifier :
'masterdata.workspace'
Note : until July 2nd, there was a typo in the frontend.groovy template where a coma (',') is missing after language:'en' that prevents the tuto from working.
This final line installs the new workspace in the application.
Congratulations! You've just defined your first Jspresso module and workspace.
The last thing we need to achieve now is to internationalize the application (at least give an english translation). We have used several translation keys even without knowing it... So open the resource bundle property file for english located here :
helloworld/core/src/main/resources/com/example/helloworld/i18n/Messages_en.properties
Copy and paste the following key/value pairs (you can easily locate them from the spring configuration files above) :
masterdata.workspace=Master Data
masterdata.workspace.description=Master data management workspace
masterdata.cities.module=Cities
masterdata.cities.module.description=Cities management module
zip=Zip Code
com.example.helloworld.model.City=City
You can of course translate also in french in the Messages_fr.properties
masterdata.workspace=R\u00E9f\u00E9rentiel
masterdata.workspace.description=Espace de gestion du r\u00E9f\u00E9rentiel
masterdata.cities.module=Villes
masterdata.cities.module.description=Module de gestion des villes
zip=C.P.
com.example.helloworld.model.City=Ville
and afterward play with the demo user language in the jaas.config file in ${TOMCAT_HOME}/conf.
We are now ready to re-package the webapp :
mvn package
And re-deploy the webapp in Tomcat.
This is a fairly basic application but don't hesitate to play with it to see how easy it is to change things; for instance, add a property to the city entity, re-generate the webapp (mvn package) and see how the application gets impacted.
Jspresso philosophy is to use sensible defaults everywhere it is possible. That's the reason why in such a few lines of code you can get things up and running. But Jspresso allows you to overload everything at every place when needed along time. This makes the development cycles really short yet robusts.
The last thing to note is that Jspresso is far from being only a CRUD framework. It's open, extensible and provides a massive amount of built-in features to virtually cover any corporate business needs.