App问题审核 - jsp页面判断根据是否有图片决定是否显示,自定义标签实例

主要结构:
1.MessageHaveImageTag.java 判断内容是否有图片的自定义标签类.
2.myland.tld 自定义文件.
3.messageQueryList.jsp 显示页面.
显示效果:



MessageHaveImageTag.java
package com.myland.framework.tags;

import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.context.WebApplicationContext;

import com.myland.framework.util.collections.ListUtil;
import com.myland.jp.common.service.MessageImageService;
import com.myland.pojo.MessageImage;

/**
 * 
 * @author lengzl
 * @email  [email protected]
 * @create 2015年7月30日 下午4:59:42
 */
public class MessageHaveImageTag extends TagSupport{

    private static final long serialVersionUID = -5234128142635788254L;
    
    /**
     * 信息id
     */
    private String messageId ;

    /**
     * 存在图片返回1 不存在则返回0
     */
    public int doStartTag() throws JspException {

        try {
            WebApplicationContext appContext = (WebApplicationContext) pageContext.getServletContext().getAttribute(
                    WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
            MessageImageService messageImageService = (MessageImageService) appContext.getBean("messageImageService");
            String html = "0";
            
            if(StringUtils.isNotBlank(messageId)){
                List<MessageImage> messageImages = messageImageService.getMdListByPid(messageId);
                if(ListUtil.isNotEmpty(messageImages)){
                    html = "1";
                }
            }
            pageContext.getOut().write(html);// 标签的返回值
            
        } catch(Exception e) {
            throw new JspTagException("封装可编辑标签出现异常");
        }
        return EVAL_BODY_INCLUDE;
    }

    /**
     *   
     */
    public int doEndTag() throws JspException {
        return EVAL_PAGE;
    }
    
    public String getMessageId() {
        return messageId;
    }

    
    public void setMessageId(String messageId) {
        this.messageId = messageId;
    }
    
}



myland.tld
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
	<tlibversion>1.0</tlibversion>
	<jspversion>1.1</jspversion>
	<shortname>myland</shortname>
	
	<!-- 分页标签 -->
	<tag>
		<name>page</name>
		<tagclass>com.myland.framework.tags.PageTag</tagclass>
		<bodycontent>JSP</bodycontent>
		<attribute>
			<name>pagination</name>
			<required>true</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
		<attribute>
			<name>showType</name>
			<required>false</required>
			<rtexprvalue>false</rtexprvalue>
		</attribute>
	</tag>
	
	<!-- 显示系统配置的基本信息 -->
	<tag>
		<name>base</name>
		<tagclass>com.myland.framework.tags.BaseInfoTag</tagclass>
		<bodycontent>JSP</bodycontent>
		<attribute>
			<name>node</name>
			<required>true</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
	</tag>
	
	<!-- 将文本设置可编辑标签 -->
	<tag>
		<name>edit</name>
		<tagclass>com.myland.framework.tags.EditTag</tagclass>
		<bodycontent>JSP</bodycontent>
		<attribute>
			<name>message</name>
			<required>true</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
		<attribute>
			<name>url</name>
			<required>true</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
		<attribute>
			<name>paramName</name>
			<required>true</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
		<attribute>
			<name>type</name>
			<required>true</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
	</tag>
	
	<!-- 权限标签 -->
	<tag>
		<name>adminx_auth</name>
		<tagclass>com.lecheng.framework.tags.AuthTag</tagclass>
		<bodycontent>JSP</bodycontent>
		<attribute>
			<name>action</name>
			<required>true</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
	</tag>
	
	<!-- 取字典信息标签 -->
	<tag>
		<name>dic</name>
		<tagclass>com.myland.framework.tags.DicTag</tagclass>
		<bodycontent>JSP</bodycontent>
		<attribute>
			<name>code</name>
			<required>true</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
		<attribute>
			<name>name</name>
			<required>true</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
		<attribute>
			<name>value</name>
			<required>true</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
		<attribute>
			<name>defaultValue</name>
			<required>false</required>
			<rtexprvalue>false</rtexprvalue>
		</attribute>
	</tag>
	
	<!-- 截取字符串标签 -->
	<tag>
		<name>str</name>
		<tagclass>com.myland.framework.tags.StrTag</tagclass>
		<bodycontent>JSP</bodycontent>
		<attribute>
			<name>str</name>
			<required>true</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
		<attribute>
			<name>length</name>
			<required>true</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
		<attribute>
			<name>mark</name>
			<required>false</required>
			<rtexprvalue>false</rtexprvalue>
		</attribute>
		<attribute>
			<name>markLength</name>
			<required>false</required>
			<rtexprvalue>false</rtexprvalue>
		</attribute>
	</tag>
	
	<!-- 获取缓存中的string类型的值 -->
	<tag>
		<name>cache</name>
		<tagclass>com.myland.framework.tags.CacheTag</tagclass>
		<bodycontent>JSP</bodycontent>
		<attribute>
			<name>cacheType</name>
			<required>true</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
		<attribute>
			<name>key</name>
			<required>true</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
	</tag>
	
	<!-- 列表序号 -->
	<tag>
		<name>index</name>
		<tagclass>com.myland.framework.tags.PageIndexTag</tagclass>
		<bodycontent>JSP</bodycontent>
		<attribute>
			<name>qc</name>
			<required>true</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
		<attribute>
			<name>step</name>
			<required>true</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
	</tag>
	
	<tag>
		<name>cookie</name>
		<tagclass>com.myland.framework.tags.CookieTag</tagclass>
		<bodycontent>JSP</bodycontent>
		<attribute>
			<name>name</name>
			<required>true</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
	</tag>
	
	<!-- 根据messageid 判断是否存在图片.使用到的★★ -->
	<tag>
		<name>isHaveMessageImage</name>
		<tagclass>com.myland.framework.tags.MessageHaveImageTag</tagclass>
		<bodycontent>JSP</bodycontent>
		<attribute>
			<name>messageId</name>
			<required>true</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
	</tag>
	
</taglib>

messageQueryList.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/adminx/commonAll.js"></script>

<script type="text/javascript">

	$(document).ready(function(){
		// 进入页面时候title不在,查询时候的title不为空,
		if($.trim("${qc.conditionsObj.title}")!=""){
			$("#title").val("${qc.conditionsObj.title}");
		}
		
	});
</script>

<div id="showMessage" class="ui_tb">
	<table id="tab"  class="table" cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
		<tr>
			<!-- <th>创建人</th> -->
			<th nowrap="nowrap">创建时间</th>
			<th nowrap="nowrap">创建标题</th>
			<th nowrap="nowrap">创建内容</th>
			<th nowrap="nowrap">操作</th>
		</tr>
		<c:choose>
			<c:when test="${empty messages}">
				<tr>
					<td colspan="6" style="text-align: center">无相关记录</td>
				</tr>
			</c:when>
			<c:otherwise>
				<c:forEach items="${messages }" var="mes" varStatus="status">
					<tr>
						<%-- <td>${mes.crtPerson}</td> --%>
						<td>${mes.crtTime }</td>
						<td>${mes.title }</td>
						<td>
						${mes.cont }
						<a href="javascript:view('${mes.id }','${mes.status }')">
						<c:set scope="page" var="isHave">
						<!-- 自定义标签的判断★ -->
							<myland:isHaveMessageImage messageId="${mes.id}"></myland:isHaveMessageImage>
						</c:set>
						<c:if test="${isHave==1}">
							<img alt="" src="${pageContext.request.contextPath }/images/adminx/common/img.jpg" style="border: 0px;" width="15"/>
						</c:if>
						</a>
						</td>
						<td> 
							<span class="chakan">
							<%-- -新建时候可以看到审核 --%>
							<c:if test="${mes.status == '0' }">
								<a href="javascript:audit('${mes.id }')" class="edit">审核</a>
							</c:if>
								<a href="javascript:viewDetailInfo('${mes.id }')">回复明细</a> <%--,'${qc.pagination.pageNum}' --%>
							</span>
							
						</td>
					</tr>
				</c:forEach>
			</c:otherwise>
		</c:choose>
	</table>
	<br>
	<div><myland:page pagination="${qc.pagination}" showType="002"/></div>
</div>

猜你喜欢

转载自timeil.iteye.com/blog/2359708