Chinaunix首页 | 论坛 | 博客
  • 博客访问: 522628
  • 博文数量: 151
  • 博客积分: 7010
  • 博客等级: 少将
  • 技术积分: 1405
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-22 14:32
文章分类

全部博文(151)

文章存档

2011年(1)

2010年(23)

2009年(1)

2008年(126)

我的朋友

分类: 系统运维

2008-09-03 11:14:27

Most real-world tag files are controlled through attribute values set by the page author.

Example 11-2. Using attributes in a tag file (motd.tag)
    <%@ tag body-content="empty" %>
    <%@ attribute name="category" required="true" %>
    <%@ taglib prefix="c" uri="" %>
   
   
   
    ${mmb.message}

Each attribute must be declared with an attribute directive in a tag file.The value the page author assigns to an attribute shows up as a page scope variable in the tag file.


Using Undeclared Attributes
The tag files can use the tag directive's "dynamic-attribute" attribute to accept undeclared attributes.This attribute declares that the tag file accepts any custom action element attribute.The attribute value is the name of a local page scope variable that holds a collection(a Map) with all undeclared attribute names and values.

Example 11-3. Using undeclared attributes in a tag file (headers.tag)
    <%@ tag body-content="empty" dynamic-attributes="dynattrs" %>
    <%@ attribute name="caption" required="true" %>
    <%@ taglib prefix="c" uri="" %>
   
         
        ${a.key}="${a.value}"
     

    >
      ${caption}
     
        Name
        Value
     
     
       
          ${h.key}
          ${h.value}
       
     

   

The dynamic-attributes attribute declares a variable named dynattrs to hold the undecalred attributes(in jsp file is the params flowed by the tag name).

This is how you can use the tag file in a JSP page:
   <%@ page contentType="text/html" %>
   <%@ taglib prefix="my" tagdir="/WEB-INF/tags/mytags" %>
  
  
    
       Headers
    
    
                border="1" cellspacing="0" cellpadding="5" />
    
  

The action element for the tag file defines values for the mandatory 'caption' attribute plus three undeclared attributes:border,cellspacing,and cellpadding.
阅读(589) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~