Call for New Batch / Any Query / Demo Classes : ☎ 08871209400 , 7987028543 , Zone-2,M.P.Nagar,Bhopal

Custom Tags with Attributes

A simple tag can have attributes. Attributes customize the behavior of a custom tag just as parameters customize the behavior of a method. There are three types of attributes:

● Simple attributes
● Fragment attributes
● Dynamic attributes

‣ Simple Attributes

Simple attributes are evaluated by the container before being passed to the tag handler. Simple attributes are listed in the start tag and have the syntax: attr="value". You can set a simple attribute value from a String constant, or an expression language (EL) expression, or by using a jsp:attribute element. The conversion process between the constants and expressions and attribute types follows the rules described for JavaBeans component properties in Setting JavaBeans Component Properties.
The first attribute, a reference to a book database object, is set by an EL expression. The second attribute, which sets the color of the rows in a table that represents the bookstore catalog, is set with a String constant.

<sc:catalog bookDB ="${bookDB}" color="#cccccc">

‣ Fragment Attributes

A JSP fragment is a portion of JSP code passed to a tag handler that can be invoked as many times as needed. You can think of a fragment as a template that is used by a tag handler to produce customized content. Thus, unlike a simple attribute which is evaluated by the container, a fragment attribute is evaluated by a tag handler during tag invocation.

To declare a fragment attribute, you use the fragment attribute of the attribute directive or use the fragment subelement of the attribute TLD element. You define the value of a fragment attribute by using a jsp:attribute element. When used to specify a fragme nt attribute, the body of the jsp:attribute element can contain only static text and standard and custom tags; it cannot contain scripting elements.
JSP fragments can be parameterized by means of expression language (EL) variables in the JSP code that composes the fragment.

The catalog tag discussed earlier accepts two fragments: normalPrice, which is displayed for a product that’s full price, and onSale, which is displayed for a product that’s on sale.

<sc:catalog bookDB ="${bookDB}" color="#cccccc">
    <jsp:attribute name="normalPrice">
    <jsp:attribute name="onSale">
        <strike><fmt:formatNumber value="${price}"
<font color="red"><fmt:formatNumber value="${salePrice}" type="currency"/></font> </jsp:attribute> </sc:catalog>

The tag executes the normalPrice fragment, using the values for the price EL variable, if the product is full price. If the product is on sale, the tag executes the onSale fragment using the price and salePrice variables.

‣ Dynamic Attributes

A dynamic attribute is an attribute that is not specified in the definition of the tag. Dynamic attributes are used primarily by tags whose attributes are treated in a uniform manner but whose names are not necessarily known at development time.
For example, this tag accepts an arbitrary number of attributes whose values are colors and outputs a bulleted list of the attributes colored according to the values:

<colored:colored color1="red" color2="yellow" color3="blue"/>

Deferred Value

A deferred value attribute is one that accepts deferred value expressions, which are described in Value Expressions.

Deferred Method

A deferred method attribute is one that accepts deferred method expressions, which are described in Method Expressions.

‣ Dynamic Attribute or Deferred Expression

This kind of attribute can accept a String literal, a scriptlet expression, or an EL expression, including deferred expressions.

jsp:attribute Element

The jsp:attribute element allows you to define the value of a tag attribute in the body of an XML element instead of in the value of an XML attribute.

For example, the Duke’s Bookstore template page screendefinitions.jsp uses jsp:attribute to use the output of fmt:message to set the value of the value attribute of tt:parameter:

<tt:screen id="/bookcatalog">
    <tt:parameter name="title" direct="true">
        <jsp:attribute name="value" >
            <fmt:message key="TitleBookCatalog"/>
    <tt:parameter name="banner" value="/template/banner.jsp"
    <tt:parameter name="body" value="/bookcatalog.jsp"

jsp:attribute accepts a name attribute and a trim attribute. The name attribute identifies which tag attribute is being specified. The optional trim attribute determines whether or not white space appearing at the beginning and end of the element body should be discarded.

An empty body is equivalent to specifying "" as the value of the attribute.

• The body of jsp:attribute is restricted according to the type of attribute being specified:
• For simple attributes that accept an EL expression, the body can be any JSP content.
• For simple attributes that do not accept an EL expression, the body can contain only static text.
• For fragment attributes, the body must not contain any scripting elements.

References : oracle « Privious Post » « Next Post » share on :        :  

Love to hear your Views / Guidance / Recommendations on this Post…

Global Tech NewsTop Programing Index January 2018January Headline Programming Language C awarded Language of the Year 2017,language C appears to be the fastest grower of 2017 in the TIOBE index and thus is declared programming language of the yearProgramming languages used in most popular websitesThe most popular websites have in common that they are dynamic websites. Their development typically involves server side coding client side coding and database technologyTop 10 Computer Science Skills That Could Sharpen Non-Computer Science CareersWhat do design marketing, engineering and data analysis have in common Theyre all careers where employers increasingly demand computer science skills.Oracle Buys AconexCreates the Worlds Most Comprehensive Cloud Offering for Managing All Aspects of Construction ProjectsOracle Unveils Worlds First Autonomous Database CloudAlso Introduces Oracle Autonomous Data Warehouse Cloud that has Demonstrated Performance of 10x Faster at Half the Cost of AmazonRecent List and Rankings Of Top Programming LanguagesThe programming languages Kotlin and C seem to be the only candidates to become programming language of the year 2017. TIOBE will announce the winner of this award next monthProgramming Index for November 2017This index ranks programming languages on the basis of their popularity.October Rankings Of Top Programming LanguagesIn the Beginning of this year the Programming Language Swift Peaked at a Rating of 2.3% in the TIOBE index and Even Reached a top 10 position. But now it is back at Position 16 and Constantly Declining Month after Month. Until recently it was quite Common to Program Android apps in Java and iOS apps in Swift/Objective-CAutosizing TextViewsAndroid O and Support Lib 26 allow to the text size expand,for Best user Experience with Text, Material Design Recommends Using a Dynamic Type Instead of smaller type Sizes or Truncating Larger-Size TextUsing Fonts in AndroidIntroduce to Android O and Support Library 26 new ways of working with Fonts. now You can Bundle Fonts as Resources by Adding the Font File in the Res/Font Folder and use it like any Other Asset in XML Layouts, Styles or Programmatically via the TypefaceSpace Station Crew Member Discusses His First Days in Space with Minnesota StudentsAboard the International Space Station, Expedition 53 Flight Engineer Mark Vande Hei of NASA fielded questions about life and work on the orbital outpost during an in-flight educational event Sept. 18 with students from the Pine River-Backus schools in Pine River, MinnesotaSpace Station Crew Members Discuss Life in Space with the MediaAboard the International Space Station, Expedition 53 Flight Engineers Mark Vande Hei and Joe Acaba of NASA and Paolo Nespoli of the European Space Agency discussed life and work aboard the orbital complex in a pair of in-flight interviews Sept. 20 with KSTP-TV, Minneapolis and the Associated Press

Call / Visit for New Batch


Why Join Us

  • ➯ Free Demo Classes
  • ➯ No Registration Fee
  • ➯ Interview Questions
  • ➯ Study Materials
  • ➯ Softwares
  • ➯ Aptitude & Reasoning
  • ➯ Placement Assitance


  • MyJava Training Institute ,
  • Plot No.243 , shop No 14 ,
  • Secnd Floor , Zone-II ,
  • M.P.Nagar , Bhopal,
  • Madhya Pradesh ( 462011 )
  • ☎  08871209400 , 7987028543
  • 🌐
FacebookGoogle +LinkedInTwitterYouTube

MyJava - java Training Institute