自定义标签

编程技术  /  houtizong 发布于 3年前   128
public class SelectTag extends TagSupport  
{  
    private String id;// ID  
 
    private String urlStr;// 服务地址  
 
    private String parms;// 参数  
 
    private SelectBean selectBean;// 返回数据  
 
    private boolean isHand = false;// 是否允许手动输入  
 
    private String cssClass;// 样式  
 
    private Boolean isPage; // 是否启动分页  
 
    private Integer pageSize; // 一页显示多少行  
 
    /** 
     * 当JSP引擎看到自己的JSP页面中包含有tag标签时,它会调用doStartTag方法来处理tag标签的开头 
     */ 
    @Override 
    public int doStartTag() throws JspException  
    {  
        // 如果body要被计算,那么doStartTag方法应返回 EVAL_BODY_INCLUDE,否则应返回SKIP_BODY  
        return EVAL_BODY_INCLUDE;  
    }  
 
    /** 
     * 调用doEndTag方法来处理tag标签的结束 
     */ 
    @Override 
    public int doEndTag() throws JspException  
    {  
 
        try 
        {  
            System.out.println();  
            // JspWriter 继承自java.io.Writer类,得到out对象  
            JspWriter out = pageContext.getOut();  
            StringBuffer total = new StringBuffer("<div class=\"" + cssClass + "\">");  
            drawSelect(total);  
            drawList(total);  
            total.append("</div>");  
            out.print(total.toString());  
        }  
        catch (IOException e)  
        {  
            e.printStackTrace();  
        }  
        // 如果余下的页面还要被计算,那它将返回EVAL_PAGE,否则将会返回SKIP_PAGE  
        return EVAL_PAGE;  
    }  
 
    /** 
     * 绘制查询条件 
     *  
     * @param total 
     *  
     */ 
    private void drawSelect(StringBuffer total)  
    {  
        total.append("<div>");  
        total.append("<input name=\"" + id + "\" type=\"text\" class=\"condition\" />");  
        total.append("<input type=\"Button\" value=\"查询\" class=\"search\" onclick=\"search('" + urlStr + "','" + id + "');\" />");  
        total.append("</div>");  
    }  
 
    /** 
     * 绘制显示列表 
     *  
     * @param total 
     *  
     */ 
    private void drawList(StringBuffer total)  
    {  
        total.append("<div id=\"" + id + "List" + "\" class=\"list\">");  
        total.append("<a alt=\"BEGIN\"></a>");  
        total.append("<table cellpadding=\"0\" cellspacing=\"0\">");  
        drawTable(total);  
        total.append("</table>");  
        if (isPage) drawPage(total);  
        total.append("<a alt=\"END\"></a>");  
        total.append("</div>");  
 
    }  
 
    /** 
     * 绘制Table 
     *  
     * @param total 
     *  
     */ 
    private void drawTable(StringBuffer total)  
    {  
        if (null != selectBean)  
        {  
            System.out.println("-------------");  
            String column = null;  
            if (selectBean.getObjs().size() <= 0)  
            {  
                total.append("<tr id=\"" + id + "Tr" + 0 + "\" onmousemove=\"addClass(" + "'" + id + "'," + 0 + ");\" onmouseout=\"removeClass(" + "'" + id + "'," + 0 + ");\"><td id=\"" + id + "Td" 
                        + 0 + "\">");  
                total.append("</td></tr>");  
            }  
            for (int i = 0; i < selectBean.getObjs().size(); i++)  
            {  
                column = selectBean.getObjs().get(i).get(id.toUpperCase()) + "";  
                if (null == column || column.equals("null")) continue;  
                total.append("<tr id=\"" + id + "Tr" + i + "\" onmousemove=\"addClass(" + "'" + id + "'," + i + ");\" onmouseout=\"removeClass(" + "'" + id + "'," + i + ");\"><td id=\"" + id + "Td" 
                        + i + "\" onclick=\"setValue(" + "'" + id + "'," + i + ");\">");  
                total.append(column);  
                total.append("</td></tr>");  
                System.out.println(column);  
            }  
        }  
    }  
 
    /** 
     * 绘制分页 
     *  
     * @param total 
     *  
     */ 
    private void drawPage(StringBuffer total)  
    {  
        if (null != selectBean && null != selectBean.getObjs())  
        {  
            if (selectBean.getObjs().size() < selectBean.getTotalCount())  
            {  
                total.append("<div class=\"listPage\">");  
                if (selectBean.isPrevious()) total.append("<a href=\"#\" onclick=\"pageSearch('" + urlStr + "','" + id + "'," + (selectBean.getStart() - 1) + ");\">上一页</a>");  
                if (selectBean.isNext()) total.append("<a href=\"#\" onclick=\"pageSearch('" + urlStr + "','" + id + "'," + (selectBean.getStart() + 1) + ");\">下一页</a>");  
                total.append("</div>");  
            }  
        }  
    }  
 
    /* ======================数据封装========================== */ 
    public String getId()  
    {  
        return id;  
    }  
 
    public void setId(String id)  
    {  
        this.id = id;  
    }  
 
    public String getUrlStr()  
    {  
        return urlStr;  
    }  
 
    public void setUrlStr(String urlStr)  
    {  
        this.urlStr = urlStr;  
    }  
 
    public String getParms()  
    {  
        return parms;  
    }  
 
    public void setParms(String parms)  
    {  
        this.parms = parms;  
    }  
 
    public SelectBean getSelectBean()  
    {  
        return selectBean;  
    }  
 
    public void setSelectBean(SelectBean selectBean)  
    {  
        this.selectBean = selectBean;  
    }  
 
    public boolean isHand()  
    {  
        return isHand;  
    }  
 
    public void setHand(boolean isHand)  
    {  
        this.isHand = isHand;  
    }  
 
    public String getCssClass()  
    {  
        return cssClass;  
    }  
 
    public void setCssClass(String cssClass)  
    {  
        this.cssClass = cssClass;  
    }  
 
    public Boolean getIsPage()  
    {  
        return isPage;  
    }  
 
    public void setIsPage(Boolean isPage)  
    {  
        this.isPage = isPage;  
    }  
 
    public Integer getPageSize()  
    {  
        return pageSize;  
    }  
 
    public void setPageSize(Integer pageSize)  
    {  
        this.pageSize = pageSize;  
    }  


public class SelectTag extends TagSupport
{
private String id;// ID

private String urlStr;// 服务地址

private String parms;// 参数

private SelectBean selectBean;// 返回数据

private boolean isHand = false;// 是否允许手动输入

private String cssClass;// 样式

private Boolean isPage; // 是否启动分页

private Integer pageSize; // 一页显示多少行

/**
* 当JSP引擎看到自己的JSP页面中包含有tag标签时,它会调用doStartTag方法来处理tag标签的开头
*/
@Override
public int doStartTag() throws JspException
{
// 如果body要被计算,那么doStartTag方法应返回 EVAL_BODY_INCLUDE,否则应返回SKIP_BODY
return EVAL_BODY_INCLUDE;
}

/**
* 调用doEndTag方法来处理tag标签的结束
*/
@Override
public int doEndTag() throws JspException
{

try
{
System.out.println();
// JspWriter 继承自java.io.Writer类,得到out对象
JspWriter out = pageContext.getOut();
StringBuffer total = new StringBuffer("<div class=\"" + cssClass + "\">");
drawSelect(total);
drawList(total);
total.append("</div>");
out.print(total.toString());
}
catch (IOException e)
{
e.printStackTrace();
}
// 如果余下的页面还要被计算,那它将返回EVAL_PAGE,否则将会返回SKIP_PAGE
return EVAL_PAGE;
}

/**
* 绘制查询条件
*
* @param total
*
*/
private void drawSelect(StringBuffer total)
{
total.append("<div>");
total.append("<input name=\"" + id + "\" type=\"text\" class=\"condition\" />");
total.append("<input type=\"Button\" value=\"查询\" class=\"search\" onclick=\"search('" + urlStr + "','" + id + "');\" />");
total.append("</div>");
}

/**
* 绘制显示列表
*
* @param total
*
*/
private void drawList(StringBuffer total)
{
total.append("<div id=\"" + id + "List" + "\" class=\"list\">");
total.append("<a alt=\"BEGIN\"></a>");
total.append("<table cellpadding=\"0\" cellspacing=\"0\">");
drawTable(total);
total.append("</table>");
if (isPage) drawPage(total);
total.append("<a alt=\"END\"></a>");
total.append("</div>");

}

/**
* 绘制Table
*
* @param total
*
*/
private void drawTable(StringBuffer total)
{
if (null != selectBean)
{
System.out.println("-------------");
String column = null;
if (selectBean.getObjs().size() <= 0)
{
total.append("<tr id=\"" + id + "Tr" + 0 + "\" onmousemove=\"addClass(" + "'" + id + "'," + 0 + ");\" onmouseout=\"removeClass(" + "'" + id + "'," + 0 + ");\"><td id=\"" + id + "Td"
+ 0 + "\">");
total.append("</td></tr>");
}
for (int i = 0; i < selectBean.getObjs().size(); i++)
{
column = selectBean.getObjs().get(i).get(id.toUpperCase()) + "";
if (null == column || column.equals("null")) continue;
total.append("<tr id=\"" + id + "Tr" + i + "\" onmousemove=\"addClass(" + "'" + id + "'," + i + ");\" onmouseout=\"removeClass(" + "'" + id + "'," + i + ");\"><td id=\"" + id + "Td"
+ i + "\" onclick=\"setValue(" + "'" + id + "'," + i + ");\">");
total.append(column);
total.append("</td></tr>");
System.out.println(column);
}
}
}

/**
* 绘制分页
*
* @param total
*
*/
private void drawPage(StringBuffer total)
{
if (null != selectBean && null != selectBean.getObjs())
{
if (selectBean.getObjs().size() < selectBean.getTotalCount())
{
total.append("<div class=\"listPage\">");
if (selectBean.isPrevious()) total.append("<a href=\"#\" onclick=\"pageSearch('" + urlStr + "','" + id + "'," + (selectBean.getStart() - 1) + ");\">上一页</a>");
if (selectBean.isNext()) total.append("<a href=\"#\" onclick=\"pageSearch('" + urlStr + "','" + id + "'," + (selectBean.getStart() + 1) + ");\">下一页</a>");
total.append("</div>");
}
}
}

/* ======================数据封装========================== */
public String getId()
{
return id;
}

public void setId(String id)
{
this.id = id;
}

public String getUrlStr()
{
return urlStr;
}

public void setUrlStr(String urlStr)
{
this.urlStr = urlStr;
}

public String getParms()
{
return parms;
}

public void setParms(String parms)
{
this.parms = parms;
}

public SelectBean getSelectBean()
{
return selectBean;
}

public void setSelectBean(SelectBean selectBean)
{
this.selectBean = selectBean;
}

public boolean isHand()
{
return isHand;
}

public void setHand(boolean isHand)
{
this.isHand = isHand;
}

public String getCssClass()
{
return cssClass;
}

public void setCssClass(String cssClass)
{
this.cssClass = cssClass;
}

public Boolean getIsPage()
{
return isPage;
}

public void setIsPage(Boolean isPage)
{
this.isPage = isPage;
}

public Integer getPageSize()
{
return pageSize;
}

public void setPageSize(Integer pageSize)
{
this.pageSize = pageSize;
}
}

Java代码
<gwzd:select pageSize="10" cssClass="default" parms="haha,hehe" 
                isPage="true" urlStr="executeTLD.action" 
                selectBean="${zsndSelectBean}" id="zsnd"></gwzd:select>  
            <gwzd:select pageSize="10" cssClass="default" parms="h,h" 
                isPage="true" urlStr="getZSXYMCTLD.action" 
                selectBean="${zsyxmcSelectBean}" id="zsyxmc"></gwzd:select> 

<gwzd:select pageSize="10" cssClass="default" parms="haha,hehe"
isPage="true" urlStr="executeTLD.action"
selectBean="${zsndSelectBean}" id="zsnd"></gwzd:select>
<gwzd:select pageSize="10" cssClass="default" parms="h,h"
isPage="true" urlStr="getZSXYMCTLD.action"
selectBean="${zsyxmcSelectBean}" id="zsyxmc"></gwzd:select>


请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!

留言需要登陆哦

技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成

网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];

      订阅博客周刊 去订阅

文章归档

文章标签

友情链接

Auther ·HouTiZong
侯体宗的博客
© 2020 zongscan.com
版权所有ICP证 : 粤ICP备20027696号
PHP交流群 也可以扫右边的二维码
侯体宗的博客