自定义标签
程序员文章站
2022-03-25 22:58:29
...
页面设定标签内容:
<td align="center">
<bean:define id="credentialId" name="result" property="credentialId"></bean:define>
<zclshtmlx:credentialTime credentialId='${credentialId}'></zclshtmlx:credentialTime>
</td>
<td align="center">
<zclshtmlx:contractEndDate credentialId='${credentialId}'></zclshtmlx:contractEndDate>
</td>
标签内容:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>1.3</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>bean</short-name>
<uri>http://localhost/tags-bean</uri>
<!-- 左菜单 -->
<tag>
<name>leftTag</name>
<tag-class>com.platform.util.tag.tag.LeftMenuTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>moduleId</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>moduleCode</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 证件类型 -->
<tag>
<name>displayCredentialTypeJspTag</name>
<tag-class>
com.platform.util.tag.type.CredentialTypeJspTag
</tag-class>
<body-content>JSP</body-content>
<description>Displays the Top Jsp</description>
<attribute>
<name>url</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 资料类型树 -->
<tag>
<name>displayMaterialTypeJspTag</name>
<tag-class>
com.platform.util.tag.type.MaterialTypeJspTag
</tag-class>
<body-content>empty</body-content>
</tag>
<!-- 人事组织机构树 -->
<tag>
<name>displayQueryPersonTreeJspTag</name>
<tag-class>
com.platform.util.tag.tag.QueryPersonTreeJspTag
</tag-class>
<body-content>empty</body-content>
<description>Displays the Top Jsp</description>
</tag>
<!-- 总部下面的单位树 -->
<tag>
<name>displayDirectUnitTreeJspTag</name>
<tag-class>
com.platform.util.tag.tag.DisplayDirectUnitTreeTag
</tag-class>
<body-content>empty</body-content>
<description>Displays the Top Jsp</description>
</tag>
<!-- 总部下面的单位部门树 -->
<tag>
<name>displayUnitDeptTreeJspTag</name>
<tag-class>
com.platform.util.tag.tag.DisplayUnitDeptTreeTag
</tag-class>
<body-content>empty</body-content>
<description>Displays the Top Jsp</description>
<attribute>
<name>url</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 角色信息管理-单位树菜单 -->
<tag>
<name>DisplayUnitTreeJspTag</name>
<tag-class>
com.platform.util.tag.tag.DisplayUnitTreeJspTag
</tag-class>
<attribute>
<name>url</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<name>write</name>
<tag-class>com.platform.util.tag.struts.taglib.bean.WriteTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>bundle</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>filter</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>format</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>formatKey</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>ignore</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>locale</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>name</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>property</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>scope</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>len</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>withDot</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>moneyFormat</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>upperFormat</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<name>dateImg</name>
<tag-class>com.platform.util.tag.tag.DateImageTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>bundle</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>filter</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>format</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>formatKey</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>ignore</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>name</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>property</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>scope</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>days</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>src</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>is_less</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<name>auth</name>
<tag-class>com.platform.util.tag.tag.AuthPermissionTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>function</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>noFunction</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>module</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>noModule</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 判断项目种类 -->
<tag>
<name>verifyProjectSort</name>
<tag-class>com.platform.util.tag.tag.VerifyProjectSortTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>projectId</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 申请单审批人 -->
<tag>
<name>approvalPerson</name>
<tag-class>com.platform.util.tag.tag.FreeApprovalPersonTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>approvalId</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 已审批-->
<tag>
<name>reApproval</name>
<tag-class>com.platform.util.tag.tag.FreeReApprovalTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>approvalId</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>objectName</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 查询流程IDS-->
<tag>
<name>queryApprovalIds</name>
<tag-class>com.platform.util.tag.tag.QueryFreeApprovalIdsTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>approvalId</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>objectName</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 查询业务申请单待批事项-->
<tag>
<name>applyApprovalItem</name>
<tag-class>com.platform.util.tag.tag.QueryApplyApprovalItemTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>approvalId</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 工作流参数设置的单位部门树 -->
<tag>
<name>processDeptPostTreeJspTag</name>
<tag-class>
com.platform.workflow.util.tag.ProcessDeptPostTreeTag
</tag-class>
<body-content>empty</body-content>
<attribute>
<name>resource</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>url</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 建造师合同时间显示 -->
<tag>
<name>constructorTime</name>
<tag-class>com.platform.util.tag.tag.ConstructorContractTimeTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>constructorId</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 人员合同时间显示 -->
<tag>
<name>personContractTime</name>
<tag-class>com.platform.util.tag.tag.PersonContractTimeTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>personId</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 证件到期时间显示 -->
<tag>
<name>credentialTime</name>
<tag-class>com.platform.util.tag.tag.CredentialTimeTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>credentialId</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 证件合同止期到期时间显示 -->
<tag>
<name>contractEndDate</name>
<tag-class>com.platform.util.tag.tag.CredentialContractEndDateTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>credentialId</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
对应标签实现类:
package com.platform.util.tag.tag;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import com.platform.base.spring.SpringContextUtil;
import com.platform.operate.credentials.pojo.Credential;
import com.platform.operate.credentials.service.CredentialInfoService;
import com.platform.util.common.DateUtil;
import com.platform.util.common.StringUtil;
import com.platform.util.constants.Constants;
/** ========================================================
* 上海建业信息科技有限公司 研发中心
* 日 期:2013-7-18 下午03:05:19
* 作 者:张俊奎
* 版 本:1.0
* 功能描述:证件到期时间显示
*
* 修订日期 修订人 描述
* 2013-7-18 张俊奎 创建
* ========================================================
*/
public class CredentialContractEndDateTag extends TagSupport{
private Long credentialId;
public int doEndTag() throws JspException
{
try
{
JspWriter out = pageContext.getOut();
HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
HttpSession session = request.getSession();
Object obj = session.getAttribute(Constants.SESSION_USER_OBJ);
Date nowTime = new Date();//当前时间
nowTime= StringUtil.DateToDate(nowTime, "yyyy-MM-dd");
if(obj == null){
out.write("请重新登录");
return super.doEndTag();
}
String endTimeStr = "";
if(StringUtil.isNotNullOrBlank(credentialId)){
CredentialInfoService credentialInfoService = (CredentialInfoService)SpringContextUtil.getBean("credentialInfoService");//bean的名称
Credential credential = (Credential) credentialInfoService.getObject(Credential.class,credentialId);
if(credential!=null&&StringUtil.isNotNullOrBlank(credential.getContractEndDate())){
//判断时间范围
Integer nowTimeInt = Integer.parseInt(StringUtil.DateToString(nowTime, "yyyyMMdd"));//当前时间
Integer endDateInt = Integer.parseInt(StringUtil.DateToString(credential.getContractEndDate(), "yyyyMMdd"));//结束时间
if(endDateInt<nowTimeInt){
//获取过期天数
int days1 = DateUtil.daysBetween(credential.getContractEndDate(), nowTime)+1;
endTimeStr = "<font style='font-weight:bold;color: red' title='本证件合同止期已过期,合同止期期限:"+StringUtil.DateToString(credential.getContractEndDate(), "yyyy年MM月dd日")+"'>已过期("+days1+")天</font>";
}else{
//获取到期天数
int days = DateUtil.daysBetween(nowTime, credential.getContractEndDate())+1;
if(days<90){
endTimeStr = "<font style='color: red;' title='距离合同止期不足三个月'>"+StringUtil.DateToString(credential.getContractEndDate(), "yyyy.MM.dd")+"</font>";
}else{
endTimeStr = StringUtil.DateToString(credential.getContractEndDate(), "yyyy.MM.dd");
}
}
}
}
out.write(endTimeStr);
}
catch (Exception ex)
{
throw new JspException(ex);
}
return super.doEndTag();
}
/**
* @return the credentialId
*/
public Long getCredentialId() {
return credentialId;
}
/**
* @param credentialId the credentialId to set
*/
public void setCredentialId(Long credentialId) {
this.credentialId = credentialId;
}
}
<td align="center">
<bean:define id="credentialId" name="result" property="credentialId"></bean:define>
<zclshtmlx:credentialTime credentialId='${credentialId}'></zclshtmlx:credentialTime>
</td>
<td align="center">
<zclshtmlx:contractEndDate credentialId='${credentialId}'></zclshtmlx:contractEndDate>
</td>
标签内容:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>1.3</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>bean</short-name>
<uri>http://localhost/tags-bean</uri>
<!-- 左菜单 -->
<tag>
<name>leftTag</name>
<tag-class>com.platform.util.tag.tag.LeftMenuTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>moduleId</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>moduleCode</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 证件类型 -->
<tag>
<name>displayCredentialTypeJspTag</name>
<tag-class>
com.platform.util.tag.type.CredentialTypeJspTag
</tag-class>
<body-content>JSP</body-content>
<description>Displays the Top Jsp</description>
<attribute>
<name>url</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 资料类型树 -->
<tag>
<name>displayMaterialTypeJspTag</name>
<tag-class>
com.platform.util.tag.type.MaterialTypeJspTag
</tag-class>
<body-content>empty</body-content>
</tag>
<!-- 人事组织机构树 -->
<tag>
<name>displayQueryPersonTreeJspTag</name>
<tag-class>
com.platform.util.tag.tag.QueryPersonTreeJspTag
</tag-class>
<body-content>empty</body-content>
<description>Displays the Top Jsp</description>
</tag>
<!-- 总部下面的单位树 -->
<tag>
<name>displayDirectUnitTreeJspTag</name>
<tag-class>
com.platform.util.tag.tag.DisplayDirectUnitTreeTag
</tag-class>
<body-content>empty</body-content>
<description>Displays the Top Jsp</description>
</tag>
<!-- 总部下面的单位部门树 -->
<tag>
<name>displayUnitDeptTreeJspTag</name>
<tag-class>
com.platform.util.tag.tag.DisplayUnitDeptTreeTag
</tag-class>
<body-content>empty</body-content>
<description>Displays the Top Jsp</description>
<attribute>
<name>url</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 角色信息管理-单位树菜单 -->
<tag>
<name>DisplayUnitTreeJspTag</name>
<tag-class>
com.platform.util.tag.tag.DisplayUnitTreeJspTag
</tag-class>
<attribute>
<name>url</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<name>write</name>
<tag-class>com.platform.util.tag.struts.taglib.bean.WriteTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>bundle</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>filter</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>format</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>formatKey</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>ignore</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>locale</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>name</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>property</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>scope</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>len</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>withDot</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>moneyFormat</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>upperFormat</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<name>dateImg</name>
<tag-class>com.platform.util.tag.tag.DateImageTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>bundle</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>filter</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>format</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>formatKey</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>ignore</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>name</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>property</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>scope</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>days</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>src</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>is_less</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<name>auth</name>
<tag-class>com.platform.util.tag.tag.AuthPermissionTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>function</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>noFunction</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>module</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>noModule</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 判断项目种类 -->
<tag>
<name>verifyProjectSort</name>
<tag-class>com.platform.util.tag.tag.VerifyProjectSortTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>projectId</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 申请单审批人 -->
<tag>
<name>approvalPerson</name>
<tag-class>com.platform.util.tag.tag.FreeApprovalPersonTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>approvalId</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 已审批-->
<tag>
<name>reApproval</name>
<tag-class>com.platform.util.tag.tag.FreeReApprovalTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>approvalId</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>objectName</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 查询流程IDS-->
<tag>
<name>queryApprovalIds</name>
<tag-class>com.platform.util.tag.tag.QueryFreeApprovalIdsTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>approvalId</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>objectName</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 查询业务申请单待批事项-->
<tag>
<name>applyApprovalItem</name>
<tag-class>com.platform.util.tag.tag.QueryApplyApprovalItemTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>approvalId</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 工作流参数设置的单位部门树 -->
<tag>
<name>processDeptPostTreeJspTag</name>
<tag-class>
com.platform.workflow.util.tag.ProcessDeptPostTreeTag
</tag-class>
<body-content>empty</body-content>
<attribute>
<name>resource</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>url</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 建造师合同时间显示 -->
<tag>
<name>constructorTime</name>
<tag-class>com.platform.util.tag.tag.ConstructorContractTimeTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>constructorId</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 人员合同时间显示 -->
<tag>
<name>personContractTime</name>
<tag-class>com.platform.util.tag.tag.PersonContractTimeTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>personId</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 证件到期时间显示 -->
<tag>
<name>credentialTime</name>
<tag-class>com.platform.util.tag.tag.CredentialTimeTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>credentialId</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- 证件合同止期到期时间显示 -->
<tag>
<name>contractEndDate</name>
<tag-class>com.platform.util.tag.tag.CredentialContractEndDateTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>credentialId</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
对应标签实现类:
package com.platform.util.tag.tag;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import com.platform.base.spring.SpringContextUtil;
import com.platform.operate.credentials.pojo.Credential;
import com.platform.operate.credentials.service.CredentialInfoService;
import com.platform.util.common.DateUtil;
import com.platform.util.common.StringUtil;
import com.platform.util.constants.Constants;
/** ========================================================
* 上海建业信息科技有限公司 研发中心
* 日 期:2013-7-18 下午03:05:19
* 作 者:张俊奎
* 版 本:1.0
* 功能描述:证件到期时间显示
*
* 修订日期 修订人 描述
* 2013-7-18 张俊奎 创建
* ========================================================
*/
public class CredentialContractEndDateTag extends TagSupport{
private Long credentialId;
public int doEndTag() throws JspException
{
try
{
JspWriter out = pageContext.getOut();
HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
HttpSession session = request.getSession();
Object obj = session.getAttribute(Constants.SESSION_USER_OBJ);
Date nowTime = new Date();//当前时间
nowTime= StringUtil.DateToDate(nowTime, "yyyy-MM-dd");
if(obj == null){
out.write("请重新登录");
return super.doEndTag();
}
String endTimeStr = "";
if(StringUtil.isNotNullOrBlank(credentialId)){
CredentialInfoService credentialInfoService = (CredentialInfoService)SpringContextUtil.getBean("credentialInfoService");//bean的名称
Credential credential = (Credential) credentialInfoService.getObject(Credential.class,credentialId);
if(credential!=null&&StringUtil.isNotNullOrBlank(credential.getContractEndDate())){
//判断时间范围
Integer nowTimeInt = Integer.parseInt(StringUtil.DateToString(nowTime, "yyyyMMdd"));//当前时间
Integer endDateInt = Integer.parseInt(StringUtil.DateToString(credential.getContractEndDate(), "yyyyMMdd"));//结束时间
if(endDateInt<nowTimeInt){
//获取过期天数
int days1 = DateUtil.daysBetween(credential.getContractEndDate(), nowTime)+1;
endTimeStr = "<font style='font-weight:bold;color: red' title='本证件合同止期已过期,合同止期期限:"+StringUtil.DateToString(credential.getContractEndDate(), "yyyy年MM月dd日")+"'>已过期("+days1+")天</font>";
}else{
//获取到期天数
int days = DateUtil.daysBetween(nowTime, credential.getContractEndDate())+1;
if(days<90){
endTimeStr = "<font style='color: red;' title='距离合同止期不足三个月'>"+StringUtil.DateToString(credential.getContractEndDate(), "yyyy.MM.dd")+"</font>";
}else{
endTimeStr = StringUtil.DateToString(credential.getContractEndDate(), "yyyy.MM.dd");
}
}
}
}
out.write(endTimeStr);
}
catch (Exception ex)
{
throw new JspException(ex);
}
return super.doEndTag();
}
/**
* @return the credentialId
*/
public Long getCredentialId() {
return credentialId;
}
/**
* @param credentialId the credentialId to set
*/
public void setCredentialId(Long credentialId) {
this.credentialId = credentialId;
}
}
上一篇: 单链表的创建及增删改查功能的实现