TLD Generator

I like JSP. I know many people won’t agree and maybe they have their reasons but I feel confortable with this tecnology. Of course, I always use MVC pattern and JSP are just the view part.

I was developing a custom tag library and when I had to write the tag library descriptor (TLD) I noticed that many of the information on it it’s already contained in the tag handlers classes (method signatures) and I could provide the missing information with some meta data in the code. So I made a little annotation-based tool for generating the TLD file. I created some annotations to express the info of the tag and its attributes. An annotation processor reads this meta data and generates the TLD in a few time. If I have to add or change a tag or an attribute name, now I save some time editing the TLD file (sometimes forgetting edit the TLD file or introducing some errors).

These are examples of the annotated tags:


@Tag
public class ExampleTag extends SimpleTagSupport{
    private String a;

    @TagAttribute(isRequired=true)
    public void setA(String a) {
        this.a = a;
    }

    @Override
    public void doTag() throws JspException, IOException {
        getJspContext().getOut().print("<h1>"+a+"</h1>");
    }

}

There is support for functions too.

public class ExampleFunction {

    @Function
    public static int add(int a, int b){
        return a+b;
    }

}

I made available the tool here. In this page, you will find more details about how to use it.

I hope you find it useful.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s