Customizing Spring Roo tagx

How to personalize Spring Roo components that are implemented over tagx files

Hi friends!

My name is Manuel and this is my first article in DISID blog. I’m a computer engineer and I have worked for more than three years in DISID as an analyst and developer of Java applications. Also I collaborated in the development of Spring Roo and gvNIX projects.

I use everyday Spring Roo project to develop Java applications, and although it is useful, for example to do repetitive tasks quickly, it offers you the possibility of customize the code that it generates with the purpose of extending its functioning. Sometimes you need to apply modifications over the tagx files defined by Spring Roo, because you need some operations that currently these tagx don’t accomplish. This is the main subject of this article: how can you customize tagx files?

To explain how to do it, I will use an example based on Spring Roo project. You will need:

  • IDE Eclipse STS.

  • An application generated from Spring Roo, for example, a project created using clinic.roo script.

Spring Roo Console

The reason that I will use it to change a tagx file is that I want to set a default value in inputs and currently this action isn’t supported by the input defined on the Spring Roo project.

Structure

Taking into account the possibility to change the version of Spring Roo while the project is developing, I recommend making a copy of the tagx that you want to modify. When a Spring Roo version in a project is changed, usually you will open the Roo console and you will execute a command to update all the tagx because these could have changed due to improvements developed in the new version. If you don’t have your own copy of the modified tagx, you will lose all your changes.

Update tags

I suggest you place your new tagx file into a folder located in the same level of the originals and give the folder a name similar to the project name. I strongly recommend this name because it is an easy way to identify your own tagx.

New structure

Finally, you need to indicate in your jspx files that you want to use your tagx file instead of the original one. To do that, you have to include the XML namespace with the route where your new tagx is defined. The last change that you will have to make, is to modify the reference of the input inside the content of the jspx by the new XML namespace defined.

Use new tag