Customising Struts2 JSP tags

March 13, 2009

Here is a possible way to customise the JSP taglib provided by the Struts2 framework.

The topics covered in this post are:

  • add a custom attribute to a given tag (e.g. TextField)
  • customise the Freemarker template to modify the generated HTML code
  • define new themes and templates
  • generate the new TLD for the customised version of the taglib
  • deploy it in a web application (WAR file)

The sample I have created implements a read-only version of the Struts2 JSP taglib: if a given attribute (i.e. viewMode) is set to true then a simple label (plain text) is rendered, instead of the html code for the input type, making the information on the form not editable.

This, in principle, achieves the same purpose as the disabled attribute but it looks much nicer on the web form.

Read the rest of this entry »