Struts 2 Tags list

Struts 2 tag List

In the Apache Struts 2 framework there is a wide range of the struts default tag library that fulfill all the requirements for the html tags the struts tags dynamically convert the contents of struts tags in html tags and send over the http protocol, there are the list of default struts 2 tags:-

Control tags:-

The Struts 2 tags have a set of tags that make it easy to control the flow of page execution. Following is the list of important Struts 2 Control Tags:

The if and else tags:- These tags perform basic condition flow found in every language. 'If' tag could be used by itself or with 'Else If' Tag and or single multiple 'Else' Tag. it controls the flow of the controler according to the need of code


The iterator tags:- These iterator will iterate over a value. An iterable value can be any of the following : java.util.Collection, java.util.Iterator. While iterating over an iterator, you can use Sort tag to sort the result or SubSet tag to to get a sub set of the list or array.


The merge tag:- These merge tag take two or more lists elements as parameters and merge them all together to form one tag element.


The append tag:- These append tag take two or more lists as parameters and append them all together.


The generator tag:- These generator tag generates an iterator based on the val attribute supplied.



Data tags:-

The action tag:- This tag enables developers to call actions directly from a JSP page by specifying the action name and an optional namespace. The body content of the tag is used to render the results from the Action. Any result processor defined for this action in struts.xml will be ignored, unless the executeResult parameter is specified in the user action.


The include tag:- These include will be used to include a JSP file in another JSP page.


The bean tag:- These bean tag instantiates a class that conforms to the JavaBeans specification. This tag has a body which can contain a number of Param elements to set any mutator methods on that class. If the var attribute is set on the BeanTag, it will place the instantiated bean into the stack's Context.


The date tag:- These date tag will allow you to format a Date in a quick and easy way. You can specify a custom format (eg. "dd/MM/yyyy hh:mm"), you can generate easy readable notations (like "in 2 hours, 14 minutes"), or you can just fall back on a predefined format with key 'struts.date.format' in your properties file.


The param tag:- These param tag can be used to parameterize other tags. This tag has the following two paramters.

    name (String) - the name of the parameter
    value (Object) - the value of the parameter

6. The property tag:- These property tag is used to get the property of a value, which will default to the top of the stack if none is specified.


7. The push tag:- These push tag is used to push value on stack for simplified usage.


8. The set tag:- These set tag assigns a value to a variable in a specified scope. It is useful when you wish to assign a variable to a complex expression and then simply reference that variable each time rather than the complex expression. The scopes available are application, session, request, page and action.


9. The text tag:- These text tag is used to render a I18n text message.


10. The url tag:- These url tag is used to create a URL.

Form tag:-

The list of form tags is a subset of Struts UI Tags. These tags help in the rendering of the user interface required for the Struts web applications and can be categorised into three categories. This chapter will take you thorugh all the three types of UI tags:

Simple UI Tags:- We have used these tags in our examples already, we will brush them in this chapter.


Group UI Tags:- The group UI tags are used to create radio button and the checkbox.


Select UI Tags:- Let us explore the different variations of the Select Tag offered by Struts.

UI Tags:-

textfield tag


password tag


textarea tag


checkbox tag


select tag


checkboxlist tag


radio tag


doubleselect tag


submit tag


Ajax tages:-

Struts uses the DOJO framework for the AJAX tag implementation. First of all, to proceed with this example, you need to add struts2-dojo-plugin-2.2.3.jar to your classpath.