Meyyappan has posted 101 posts at DZone. View Full User Profile

Struts 2 Data Tags Tutorial

06.14.2012
| 31069 views |
  • submit to reddit

Struts 2 Data Tags Example

In this example you will learn how to use the property tag, the set tag and the push tag. These tags are part of the Struts 2 Data Tags. Before we see the syntax of each tag you need to know what an ActionContext and a ValueStack is.

 

  • The ActionContext is a global storage area that holds all the data associated with the processing of a request.
  • The ActionContext is thread local this makes the Struts 2 actions thread safe.
  • The ValueStack is the part of the ActionContext. In Struts 2 actions resides on the ValueStack.
The Property Tag

The property tag is used to retrive the data from the ValueStack or some other object in the ActionContext like application or seesion. Let's see how to display the following details using the property tag.

Our Action class AlbumInfoAction contains the following piece of code.

package vaannila;

public class AlbumInfoAction{

    private String title;
    private Artist artist;

    public String populate()
    {
        title = "Thriller";
        artist = new Artist("Michael Jackson","King of pop");
        return "populate";
    }

    public String execute()
    {
        return "success";
    }

    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public Artist getArtist() {
        return artist;
    }
    public void setArtist(Artist artist) {
        this.artist = artist;
    }

}

Published at DZone with permission of its author, Meyyappan Muthuraman.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags: