关闭

2.11.4 带属性的标签

263人阅读 评论(0) 收藏 举报
分类:

1.WEB-INF/lib

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd">
	<description>
  		<![CDATA[".........."]]>
	</description>
  <display-name>Custom Struts Tags</display-name>
  <tlib-version>1.0</tlib-version>
  <short-name>xue</short-name>
  <uri>/xue-tags</uri>
  <tag>
		<description><![CDATA[Render an HTML input field of type button]]></description>
		<name>button</name>
		<tag-class>com.xue.frame.core.tag.HelloTag</tag-class>
		<body-content>JSP</body-content>
		<!-- 
		<dynamic-attributes>true</dynamic-attributes>
		 -->
		<attribute>
			<description><![CDATA[Set the html accesskey attribute on rendered html element]]></description>
			<name>id</name>
			<required>true</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
		<attribute>
			<description><![CDATA[The css class to use for element]]></description>
			<name>value</name>
			<required>false</required>
			<rtexprvalue>false</rtexprvalue>
	    </attribute>
	    <attribute>
	      <description><![CDATA[The css class to use for element]]></description>
	      <name>styleClass</name>
	      <required>false</required>
	      <rtexprvalue>false</rtexprvalue>
	    </attribute>
	    <attribute>
	      <description><![CDATA[The css class to use for element]]></description>
	      <name>permission</name>
	      <required>false</required>
	      <rtexprvalue>false</rtexprvalue>
	    </attribute>
  </tag>
</taglib>


2. 

 

public class HelloTag extends TagSupport { 
	private static final long serialVersionUID = 9171755382967196868L;
	// 按钮id
	private String id = "";
	// 按钮Label
	private String value = "";  
	// 按钮Class
	private String styleClass = "";
	// 权限
	private boolean permission = true;

 
	@Override
	public int doEndTag() throws JspException {
		return EVAL_PAGE;
	}


	@Override
	public int doStartTag() throws JspException {
		try {
			// session取得
			HttpSession session = pageContext.getSession();
			// 按钮生成
			StringBuffer buffer = new StringBuffer("<input"); 
			buffer.append(" type='button' "); 
 
			buffer.append("/>");
			pageContext.getOut().println(buffer.toString());
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		return SKIP_BODY;
	}


	
	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}


	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}


	/**
	 * @return the value
	 */
	public String getValue() {
		return value;
	}


	/**
	 * @param value
	 *            the value to set
	 */
	public void setValue(String value) {
		this.value = value;
	}


	/**
	 * @return the styleClass
	 */
	public String getStyleClass() {
		return styleClass;
	}


	/**
	 * @param styleClass the styleClass to set
	 */
	public void setStyleClass(String styleClass) {
		this.styleClass = styleClass;
	}


	/**
	 * @return the permission
	 */
	public boolean isPermission() {
		return permission;
	}


	/**
	 * @param permission the permission to set
	 */
	public void setPermission(boolean permission) {
		this.permission = permission;
	}  
	
}


3.

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%> 
<%@ taglib prefix="xue" uri="/xue-tags" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	 
</head>
	<body>  
     		<xue:button id="querybutton" value="自定义button" styleClass="button" permission="true"/>			 
	</body>
</html> 



0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:28368次
    • 积分:872
    • 等级:
    • 排名:千里之外
    • 原创:60篇
    • 转载:6篇
    • 译文:1篇
    • 评论:0条