Struts2 Tag Guide

Last modified by Ken McWilliams on 2012/04/05 01:21

The first place to look for tag information should always be the Tag Reference at struts.apache.org.

There are five categories of Struts2 tags (which can be clearly seen in the above mentioned Tag Reference):

  1. Data
  2. Form
  3. Control
  4. Non-Form UI
  5. Ajax

Data tags are used to output data to a Java Server Page (JSP).  Typical uses include displaying values collected by the action and displaying links to other actions.

Form tags can display data like Data tags as they can supply a default value, but are used to render html form elements.  Note: Struts2 Form tags render using a theme, so if you find it difficult to lay out the page as you would expect I would recommend changing the theme to simple.

Control tags cover: conditions, iteration and tags that manipulate collections.

Non-Form UI tags allow you to display action messages, errors for fields or for the action and let you render custom components that you have made in other JSPs, freemarker or velocity.

Ajax tags: DON'T USE THEM.  They have been deprecated.  People hearing this decide that the Struts2 jQuery Tag library is the way to go.  This too is generally not a good idea, the most flexible solution is to use JavaScript along with the struts2-json-plugin.  This needs a larger discussion and will be covered at a later date. 

Guide to Implementing your own Struts2 Tags

Here is a useful example implementing a Struts2 tag: http://joshuajava.wordpress.com/2008/12/27/creating-custom-components-with-struts-2/

[In progress]