background image

Two Fragment Attributes

<< Simple Attribute Example | Dynamic Attribute Example >>
<< Simple Attribute Example | Dynamic Attribute Example >>

Two Fragment Attributes

formatting of the book price is determined by two fragment attributes, normalPrice and
onSale
, that are conditionally invoked by the tag according to data retrieved from the book
database.
<sc:catalog bookDB =
"${bookDB}" color="#cccccc">
<jsp:attribute name=
"normalPrice">
<fmt:formatNumber value=
"${price}" type="currency"/>
</jsp:attribute>
<jsp:attribute name=
"onSale">
<strike>
<fmt:formatNumber value=
"${price}" type="currency"/>
</strike><br/>
<font color=
"red">
<fmt:formatNumber value=
"${salePrice}" type="currency"/>
</font>
</jsp:attribute>
</sc:catalog>
The screen produced by
tut-install/javaeetutorial5/examples/web/bookstore3/web/bookcatalog.jsp is shown in
Figure 8­2
. You can compare it to the version in
Figure 5­2
.
Encapsulating Reusable Content Using Tag Files
Chapter 8 · Custom Tags in JSP Pages
245