package com.yanek.cms.tag;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;

import com.yanek.cms.vo.UserInfo;

public class UserListTag extends BodyTagSupport {

	private String name;// 一个属性名
	private Iterator it;// 要迭代的对象
	private int cateid; // 用户类别id

	@Override
	public int doEndTag() throws JspException {
		try {
			if (bodyContent != null) {
				bodyContent.writeOut(bodyContent.getEnclosingWriter());
			}
		} catch (IOException e) {
			e.printStackTrace();

		}
		return EVAL_PAGE;
	}

	@Override
	public int doStartTag() throws JspException {

		//这里根据用户类型,构造不同的列表数据,实现可以根据数据库获取
		List<UserInfo> users = new ArrayList<UserInfo>();
		if (cateid == 1) {
			users.add(new UserInfo("张三", 20, "Zhangsan@163.com"));

			users.add(new UserInfo("李四", 30, "Lisi@sina.com"));
		} else {
			users.add(new UserInfo("王五", 33, "Wangwu@qq.com"));
			users.add(new UserInfo("赵六", 33, "zhaoliu@qq.com"));
		}
		it = users.iterator();

		if (it == null) {
			return SKIP_BODY;

		} else {
			return continueNext();
		}
	}

	private int continueNext() {
		if (it.hasNext()) {
			pageContext.setAttribute(name, it.next(), pageContext.PAGE_SCOPE);
			return EVAL_BODY_TAG;
		} else {

			return SKIP_BODY;
		}
	}

	@Override
	public int doAfterBody() {
		return continueNext();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getCateid() {
		return cateid;
	}

	public void setCateid(int cateid) {
		this.cateid = cateid;
	}

}
最近下载更多
329512801  LV28 2022年1月18日
xiaoding1999  LV7 2021年2月3日
goldcoast  LV1 2019年5月17日
2309094456  LV12 2018年4月25日
gypgyp  LV10 2018年3月12日
fzwvvv  LV2 2017年10月16日
xiaojia  LV1 2017年7月25日
张伟蕾  LV1 2015年4月1日
annoby  LV23 2014年6月16日
llh  LV15 2013年10月21日
最近浏览更多
lvhongquan  LV11 2023年12月30日
Tg171017  LV12 2023年6月7日
13133117021  LV4 2023年5月21日
a197304a 2023年1月8日
暂无贡献等级
微信网友_5992582549164032  LV6 2022年12月28日
微信网友_6206233028890624  LV2 2022年11月10日
陨石承影  LV1 2022年10月21日
SQ2930501923  LV14 2022年10月15日
小丶无奈  LV10 2022年6月15日
19215120437  LV2 2022年5月19日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友