Struts2 控制 标签 之 Merge Tag

Merge Tag

 

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 merge iterator causes each merge iterator to have a chance to expose its element, subsequently next call allows the next iterator to expose its element. Once the last iterator is done exposing its element, the first iterator is allowed to do so again (unless it is exhausted of entries).

In the current example, 2 lists being merged, each list have 5 entries, the following will be the logic.

  1. Display first element of the first list.
  2. Display first element of the second list.
  3. Display second element of the first list.
  4. Display second element of the second list.
  5. Display third element of the first list.
  6. Display thrid element of the second list.....and so on.

Add the following code snippet into the struts.xml file.

struts.xml

<action name="mergeTag" class="net.roseindia.mergeTag">
  <result>/pages/genericTags/mergeTag.jsp</result>
</action>

Create two lists in the action class  and populate them with various items as shown in the  "mergeTag" class.

mergeTag.java

package net.roseindia;
import com.opensymphony.xwork2.ActionSupport;
import java.util.*;

public class mergeTag extends ActionSupport {
  private List myList;
  private List myList1;

  public String execute() throws Exception{
  myList = new ArrayList();
  myList.add("www.Roseindia.net");
  myList.add("Deepak Kumar");
  myList.add("Sushil Kumar");
  myList.add("Vinod Kumar");
  myList.add("Amit Kumar");

  myList1 = new ArrayList();
  myList1.add("www.javajazzup.com");
  myList1.add("Himanshu Raj");
  myList1.add("Mr. khan");
  myList1.add("John");
  myList1.add("Ravi Ranjan");
  return SUCCESS;
  }

  public List getMyList(){
  return myList;
  }

  public List getMyList1(){
  return myList1;
  }
}

 

 

Now create a jsp page using <s:merge> and <s:param value> tags as  shown in the mergeTag.jsp page. The merge  tag  is used to merge iterators. The "id" parameter keeps the resultant iterator stored under in the stack's context and the "value" parameter in the <s:iterator> is used to get the values contained within the respective iterators.

mergeTag.jsp 

<%taglib prefix="s" uri="/struts-tags" %>

<html>
  <head>
  <title>Merge Tag Example!</title>
  </head>
  <body>
  <h1><span style="background-color: #FFFFcc">Merge Tag Example!
</span></h1>

  <s:merge id="mergeId">
  <s:param value="%{myList}" />
  <s:param value="%{myList1}" />
  </s:merge>

  <s:iterator value="%{#mergeId}">
  <s:property /><br>
  </s:iterator>
  </body>
</html>

Output of merge Tag:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值