Struts 2 Data Tags - Apache Struts 2

What are data tags?

The Struts 2 data tags are basically used to manipulate the data displayed on a page. Listed below are the important 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.
Check Detailed Example

The include tag

These include will be used to include a JSP file in another JSP page.
Check Detailed Example

The bean tag

These bean tag instantiates a class that confirms to the JavaBeans specification. This tag has a body which contains a number of Param elements to set any mutator methods on that class. If the variable attribute is set on the BeanTag, it will place the instantiated bean into the stack's Context.
Check Detailed Example

The date tag

These date tag will obviously allow you to format a Date in a quick and easy way. You can give a specific 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.
Check Detailed Example

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
Check Detailed Example

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.
Check Detailed Example

The push tag:

These push tag is used to push value on stack for simplified usage.
Check Detailed Example

The set tag

These set tags assigns a value to a variable in a particular scope. It is useful when you want to assign a variable to a complex expression and simply refer that variable each time rather than using the complex expression again. The scopes available are application, session, request, page and action.
Check Detailed Example

The text tag

These text tag is used to render a I18n text message.
Check Detailed Example

The url tag

These url tag is used to create a URL.

Click for detailed example

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Apache Struts 2 Topics