2.11.4 带属性的标签

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> 



阅读更多
想对作者说点什么? 我来说一句

jsp自定义带属性标签

2008年12月17日 3KB 下载

Nexus OSS 2.11.4

2015年09月12日 67.65MB 下载

属性不带标签体的标签实例

2008年03月26日 387KB 下载

scala-2.11.4.tar

2016年03月03日 28.63MB 下载

没有更多推荐了,返回首页

不良信息举报

2.11.4 带属性的标签

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭