<转>java自定义标签代码
程序员文章站
2024-02-04 21:07:28
...
--------------------javaBean---------------
AuditingMSSqlIMp.java文件
--------------------页面使用文件---------------
auditing_Query.jsp 页面使用文件
--------------------配置页面使用的属性---------------
--------------------配置标签使用类---------------
--------------------页面属性配置文件---------------
eline-auditing.tld文件 自定义标签配置属性文件
--------------------以上流程自定义标签实现---------------
AuditingMSSqlIMp.java文件
public Page getAuditingListPage(int pageIndex, int pageSize,int userId) throws SQLException {
// TODO Auto-generated method stub
Page page = new Page();
Connection conn = null;
CallableStatement stmt = null;
ResultSet rst = null;
try{
String str="{call dbo.up_auditingList(?,?,?)}";
conn = super.getDBConnection();
stmt = conn.prepareCall(str);
stmt.setInt(1, pageIndex);
stmt.setInt(2, pageSize);
stmt.setInt(3, userId);
rst = stmt.executeQuery();
while(rst.next()){
LpReadObj auditing = new LpReadObj();
auditing.setRegionName(rst.getString("regionName"));
auditing.setRealName(rst.getString("realName"));
auditing.setUserName(rst.getString("userName"));
auditing.setApplyLpCount(rst.getInt("Ah_applyLpcount"));
auditing.setApprovalCount(rst.getInt("ah_approvalCount"));
auditing.setType(rst.getInt("ah_type"));
auditing.setApplyDate(rst.getString("ah_applydate"));
page.getItems().add(auditing);
}
if (stmt.getMoreResults()) {
rst = stmt.getResultSet();
if (rst.next()) {
page.setTotalRecords(rst.getInt(1));
}
}
}catch (SQLException e) {
throw e;
}finally{
super.closeResultSet(rst);
super.closeStatement(stmt);
super.closeConnection(conn);
}
return page;
}
--------------------页面使用文件---------------
auditing_Query.jsp 页面使用文件
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ page import="com.eline.epicc.user.*"%>
<%@ page import="com.eline.epicc.user.model.*"%>
<%@ taglib uri="/tlds/eline-common.tld" prefix="common1"%>
<%@ taglib uri="/tlds/eline-auditing.tld" prefix="auditing1"%>
<%
User user = Users.getUser();
if (user == null || user.getUserId() == 0) {
System.out.println("Can not get instance of current user.");
user = Users.getAnonymousUser();
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<auditing1:auditingListQuery id="auditingList1" userId="<%=user.getUserId()%>" pageSize="10">
<table class="clsDataList" cellspacing="0" width="100%" border="1" cellpadding="1">
<tr height="30">
<th align="center" nowrap width="12%">分公司</th>
<th align="center" nowrap width="10%">真实姓名</th>
<th align="center" nowrap width="10%">登陆名称</th>
<th align="center" nowrap width="4%">申请号码数</th>
<th align="center" nowrap width="4%">批准号码数</th>
<th align="center" nowrap width="5%">二维码类型</th>
<th align="center" nowrap width="10%">批复日期</th>
</tr>
<common1:items>
<tr height="25">
<td align="center" width="12%"><auditing1:auditingQueryAttribute name="regionName" /></td>
<td align="center" width="10%"><auditing1:auditingQueryAttribute name="realName" /></td>
<td align="center" width="10%"><auditing1:auditingQueryAttribute name="userName" /></td>
<td align="center" width="4%"><auditing1:auditingQueryAttribute name="applyLpCount" /></td>
<td align="center" width="4%"><auditing1:auditingQueryAttribute name="approvalCount" /></td>
<td align="center" width="5%"><auditing1:auditingQueryAttribute name="type" /></td>
<td align="center" width="10%"><auditing1:auditingQueryAttribute name="applyDate" /></td>
</tr>
</common1:items>
</table>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td><common1:summaryForm /></td>
<td align="right">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><common1:numberForm>
<input type="submit" value="GO"
style="HEIGHT: 20px; FONT-FAMILY:SimSun" />
</common1:numberForm></td>
<td valign="bottom"><common1:firstForm>
<input class="clsBtnPager" type="submit" value="7">
</common1:firstForm></td>
<td valign="bottom"><common1:prevForm>
<input class="clsBtnPager" type="submit" value="3">
</common1:prevForm></td>
<td valign="bottom"><common1:nextForm>
<input class="clsBtnPager" type="submit" value="4">
</common1:nextForm></td>
<td valign="bottom"><common1:lastForm>
<input class="clsBtnPager" type="submit" value="8">
</common1:lastForm></td>
</tr>
</table>
</td>
</tr>
</table>
</auditing1:auditingListQuery>
--------------------配置页面使用的属性---------------
package com.eline.epicc.auditing.taglib;
import org.blue.util.StringUtils;
import com.eline.epicc.auditing.model.LpReadObj;
import com.eline.epicc.insurance.Insurances;
import com.eline.epicc.taglib.ItemAttributeTag;
public class AuditingQueryAttributeTag extends ItemAttributeTag {
/**
*
*/
private static final long serialVersionUID = 1L;
protected String createText() {
LpReadObj obj = (LpReadObj) item;
if (name.equalsIgnoreCase("regionName")) {
return "" + obj.getRegionName();
} else if (name.equalsIgnoreCase("userName")) {
return "" + obj.getUserName();
}else if (name.equalsIgnoreCase("realName")) {
return "" + obj.getRealName();
}else if(name.equalsIgnoreCase("mobilePIN")){
return "" + StringUtils.toString(obj.getMobilePIN());
}else if(name.equalsIgnoreCase("applyLpCount")){
return "" + StringUtils.toString(obj.getApplyLpCount());
}else if(name.equalsIgnoreCase("approvalCount")){
return "" + StringUtils.toString(obj.getApprovalCount());
}else if(name.equalsIgnoreCase("type")){
return "" + Insurances.getTypeMessage(obj.getType());
}else if(name.equalsIgnoreCase("applyDate")){
String aa = StringUtils.toString(obj.getApplyDate());
String bb = aa.substring(0, 11);
return "" + bb;
}
return null;
}
}
--------------------配置标签使用类---------------
package com.eline.epicc.auditing.taglib;
import java.util.Collection;
import javax.servlet.http.HttpServletRequest;
import com.eline.epicc.auditing.Auditings;
import com.eline.epicc.taglib.ListTag;
import com.eline.epicc.taglib.SortOrder;
import com.eline.epicc.user.Users;
import com.eline.epicc.user.model.SortUsersBy;
import com.eline.epicc.user.model.User;
import com.eline.epicc.taglib.Page;
public class AuditingQueryTag extends ListTag {
/**
*
*/
private static final long serialVersionUID = 1L;
protected final String prefix = "UserList_";
protected boolean hasNext = false;
private String regionName;//分公司
private String userName;//姓名
private String realName;
private int userId;
protected int sortBy = SortUsersBy.Username;
protected int sortOrder = SortOrder.Ascending;
protected String usernameFilter = null;
private int tatalCount;
private int doneCount;
private int remainCount;
private int unApplyCount;
private int approvalCount;
private int type;
//审核记录
private String mobilePIN;//TEL
private int applyLpCount;//applyCount
private String applyDate; //审核日期
public String getApplyDate() {
return applyDate;
}
@Override
protected Collection findCollection() throws Exception {
// TODO Auto-generated method stub
Collection coll = null;
Page page = null;
User user = Users.getUser();
if (user == null || user.getUserId() == 0)
throw new Exception("Can not get instance of current user.");
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
// 保证每次调用该列表页面时总显示第一页
if (request.getParameter(getParamPrefix() + "pageIndex") == null
|| request.getParameter(super.getParamPrefix() + "pageIndex").equals("")
|| request.getParameter(getParamPrefix() + "pageIndex").equalsIgnoreCase("null"))
pageIndex = 0;
page = Auditings.readAuditingList(pageIndex,pageSize,user.getUserId());
coll = page.getItems();
System.out.println("page.size()=" + page.getSize());
// 为基类相应属性赋值,写共几条记录,共几页第几页用
totalRecords = page.getTotalRecords(); // 共有多少条记录
//totalRecords = 5;
totalPages = (totalRecords + pageSize - 1) / pageSize; // 共有多少页
// 是否有下页
hasNext = ((pageIndex + 1) < totalRecords) ? true : false;
return coll;
}
@Override
protected void initParamPrefix() {
super.paramPrefix = this.prefix;
}
public void setUsernameFilter(String usernameFilter) {
if (usernameFilter != null
&& (usernameFilter.length() == 0 || usernameFilter.equalsIgnoreCase("null")))
this.usernameFilter = null;
else
this.usernameFilter = usernameFilter;
}
@Override
protected boolean needsNextForm() {
// TODO Auto-generated method stub
return hasNext;
}
}
--------------------页面属性配置文件---------------
eline-auditing.tld文件 自定义标签配置属性文件
<?xml version="1.0" encoding="GB2312"?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<!-- a tag library descriptor -->
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>waftemplate</shortname>
<uri></uri>
<info>EPicc Web Application Framework Template Tags</info>
<!--
二维码列表显示
-->
<tag>
<name>auditingAttribute</name>
<tagclass>com.eline.epicc.auditing.taglib.AuditingAttributeTag</tagclass>
<bodycontent>empty</bodycontent>
<info>用于二维码分配的详细信息</info>
<!-- default is "name" -->
<attribute>
<name>name</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<name>auditingQueryAttribute</name>
<tagclass>com.eline.epicc.auditing.taglib.AuditingQueryAttributeTag</tagclass>
<bodycontent>empty</bodycontent>
<info>用于二维码分配的详细信息</info>
<!-- default is "name" -->
<attribute>
<name>name</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<name>auditingListQuery</name>
<tagclass>com.eline.epicc.auditing.taglib.AuditingQueryTag</tagclass>
<bodycontent>JSP</bodycontent>
<info>用于求出符合条件的二维码信息列表</info>
<!-- id字符串 -->
<attribute>
<name>id</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>userId</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<!-- 每页最大记录数 -->
<attribute>
<name>pageSize</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<!-- 第几页 -->
<attribute>
<name>pageIndex</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<!-- 排序字段 -->
<attribute>
<name>sortBy</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>sortOrder</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<!-- 分公司 -->
<attribute>
<name>regionName</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<!-- (手机)姓名 -->
<attribute>
<name>userName</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<!-- 姓名 -->
<attribute>
<name>realName</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<!-- 电话号码 -->
<attribute>
<name>mobilePIN</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<!-- 申请号码数-->
<attribute>
<name>applyLpCount</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<!-- 批准号码数-->
<attribute>
<name>approvalCount</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<!--二维码类型-->
<attribute>
<name>type</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<!--审核日期-->
<attribute>
<name>applyDate</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
--------------------以上流程自定义标签实现---------------
上一篇: 小白爬虫第一弹之抓取妹子图
下一篇: webpack讲解(完结篇)