Struts 2 Tags Examples
In this section we are discussing the Struts 2 tags with examples. Struts 2 tags provides easy to use custom tags to help the developers to make GUI for their struts 2 based applications.
In Struts 2 there are many easy to use tags and the learning process for these tags are also easy.
There are two types of tags in Struts 2, Control Tags and Data Tags.
We will show you all the tags with good working examples. Please browse the following links to learn Struts 2 tags in detail.
Struts 2 Tags:
- Control Tags
- Control Tags-If / Else If / Else
In this section we are going to discuss the various control tags ( The Control Tags are used for flow control, such if, else and iterate.).
- Append Tag
(Control Tags) Example
In this section, we are going to describe the append tag . The append tag is a generic tag that is used to merge multiple iterators into one iterator.
- Generator Tag
(Control Tags) Example
In this section, we are going to describe the generator tag . The generator tag is a generic tag that is used to generate iterators based on different attributes passed .
- Generator
Tag (Control Tags) Using Count Attributes
In this section, we are going to describe the generator tag using thecount
attributes.
- Generator
Tag (Control Tags) Using an Iterator with Id Attributes
In this section, we are going to describe the generator tag using the id attributes.
- Iterator Tag
(Control Tags) Example
In this section, we are going to describe the Iterator tag. Iterator tag is used to iterate over a value. An iterable value can be either of: java.util.Collection, java.util.Iterator.
- Merge Tag (Control
Tags) Example
In this section, we are going to describe the merge tag . The merge tag is a generic tag that is used to merge iterators. The successive call to the merged iterator causes each merge iterator to have a chance to expose its element, subsequently next call allows the next iterator to expose its element.
- Subset Tag (Control
Tags) Example
In this section, we are going to describe the subset tag . The subset tag is a generic tag that takes an iterator and outputs a subset of it. It delegates to org.apache.struts2.util.SubsetIteratorFilter internally to perform the subset functionality.
- Subset Tag
(Control Tags) Example Using Count
In this section, we are going to describe the subset tag using the count parameter. The count parameter indicate the number of entries to be set in the resulting subset iterator.
- Subset Tag
(Control Tags) Example Using Start
In this section, we are going to describe the subset tag using the start parameter. The start parameter is of integer type. It indicates the starting index (eg. first entry is 0) of entries in the source (needed to make available as the first entry in the resulting subset iterator).
- Control Tags-If / Else If / Else
-
Data Tags
- Action Tag (Data
Tag) Example
In this section, we are going to describe the action tag . The action tag is a generic tag that is used to call actions directly from a JSP page by specifying the action name and an optional namespace.
- Bean Tag (Data Tag)
Example
In this section, we are going to describe the Bean Tag . The Bean tag is a generic tag that is used to instantiates a class that conforms to the JavaBeans specification.
- Date Tag (Data Tag)
Example
In this section, we are going to describe the Date tag .The date tag allows to format a Date in a quick and easy way. User can specify a custom format (eg. "dd/MM/yyyy hh:mm"), can generate easy readable notations (like "in 2 hours, 14 minutes"), or can just fall back on a predefined format with key 'struts.date.format' in the properties file.
- Include Tag (Data
Tag) Example
In this section, we are going to describe the include tag . The include tag is a generic tag that is used to include a servlet's output (result of servlet or a JSP page) to the current page.
- Param Tag (Data
Tag) Example
In this section, we are going to describe the param tag. The param tag is a generic tag that is used to parameterize other tags. For example the include tag and bean tag. The parameters can be added with or without a name as a key.
- Set Tag (Data Tag)
Example
In this section, we are going to describe the Set tag . The set tag is a generic tag that is used to assign a value to a variable in a specified scope.
- Text Tag (Data Tag)
Example
In this section, we are going to describe the text tag. The text tag is a generic tag that is used to render a I18n text message.
- Property Tag
(Data Tag) Example
In this section, we are going to describe the property tag . The property tag is a generic tag that is used to get the property of a value, which will default to the top of the stack if none is specified.
- Action Tag (Data
Tag) Example