Apache Jakarta and Beyond: A Java Programmeramp;#039;s Introduction [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Apache Jakarta and Beyond: A Java Programmeramp;#039;s Introduction [Electronic resources] - نسخه متنی

Larne Pekowsky

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید







18.2. Tags with Bodies


Custom tags can do more than just output data controlled by parameters. A custom tag can have a body, which it can control in arbitrary ways. Listing 18.2 shows such a custom tag that can be used to display its body, hide it, or even reverse it. The result is shown in Figure 18.1.


Figure 18.1. The result of a custom tag.

[View full size image]


Listing 18.2. A custom tag with a body


<%@ taglib prefix="awl"
uri="http://jspbook.awl.com/samples" %>
<awl:maybeShow show="no">
You can't see me!
</awl:maybeShow><br>
<awl:maybeShow show="yes">
The time is:
<awl:date format="hh:mm:ss MM/dd/yy"/>
</awl:maybeShow><br>
<awl:maybeShow show="reverse">
The time is:
<awl:date format="hh:mm:ss MM/dd/yy"/>
</awl:maybeShow><br>

This example loads the same tag library as used in Listing 18.1 and again specifies that it will be using the awl prefix to access the tags. The tag used this time is called awl:maybeShow, and it has a parameter called show that controls what the tag should do with its body. show may be set to "no," in which case the body is hidden from the page; "yes," in which case the body is displayed; or "reverse," in which case the body is shown backward.

Note that the body of the awl:maybeShow tag may include anything, including other JSP tags. This will be true of any custom tag that has been properly programmed. This property is described by saying that JSP tags can be

nested. From here on it will be assumed that the body of any tag can contain any other tag unless otherwise noted.


/ 207