Thursday, July 8, 2010

Struts2 Control Tag Append Tag Example


Struts2 Append Tag Example

Aim:
            Append tag is used to merge multiple iterators into one iterator.

Append Iterator Tag  is used to append iterators to form an appended iterator through which the entries goes from one iterator to another after each respective iterator is exhausted of entries.


Procedure:

            Step 1:

                        Create project AppendPro

                        I have already explained how to create project for struts2.

            Step 2:

                        Create Action AppendAction

                        I have already explained how to create action class in previous post.

                        Refer previous post to create Action.

                        Include following coding into AppendAction

package example;
import com.opensymphony.xwork2.ActionSupport;
import java.util.*;
import java.util.ArrayList;
public class AppendAction extends ActionSupport
{
    private ArrayList myList1;
    private ArrayList myList2;

    public ArrayList getMyList1() {
        return myList1;
    }

    public void setMyList1(ArrayList myList1) {
        this.myList1 = myList1;
    }

    public ArrayList getMyList2() {
        return myList2;
    }

    public void setMyList2(ArrayList myList2) {
        this.myList2 = myList2;
    }

    public AppendAction()
    {
    }
    public String execute() throws Exception
    {
        myList1=new ArrayList();
        myList1.add("suresh");
        myList1.add("kumar");
        myList1.add("praba");

        myList2=new ArrayList();
        myList2.add("chandru");
        myList2.add("sakthi");
        myList2.add("pavi");

        return "success";
    }

}

Step 3:

          Create jsp files home.jsp and success.jsp

           home.jsp

No comments:

Post a Comment