9 Copyright © 2005, Oracle. All rights reserved. Modularizing JavaServer Pages Development with Tags.

Slides:



Advertisements
Similar presentations
Using the SQL Access Advisor
Advertisements

Chapter 7 Constructors and Other Tools. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 7-2 Learning Objectives Constructors Definitions.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Copyright © 2003 Pearson Education, Inc. Slide 7-1 Created by Cheryl M. Hughes The Web Wizards Guide to XML by Cheryl M. Hughes.
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 3 CPUs.
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
UNITED NATIONS Shipment Details Report – January 2006.
RXQ Customer Enrollment Using a Registration Agent (RA) Process Flow Diagram (Move-In) Customer Supplier Customer authorizes Enrollment ( )
Communicating in J2EE.
19 Copyright © 2005, Oracle. All rights reserved. Distributing Modular Applications: Developing Web Services.
21 Copyright © 2005, Oracle. All rights reserved. Oracle Application Server 10g Transaction Support.
1 Copyright © 2005, Oracle. All rights reserved. Introduction.
18 Copyright © 2005, Oracle. All rights reserved. Distributing Modular Applications: Introduction to Web Services.
4 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: Servlets.
16 Copyright © 2005, Oracle. All rights reserved. Developing Message-Driven Beans.
11 Copyright © 2005, Oracle. All rights reserved. Creating the Business Tier: Enterprise JavaBeans.
3 Copyright © 2005, Oracle. All rights reserved. Basic Java Syntax and Coding Conventions.
11 Copyright © 2005, Oracle. All rights reserved. Using Arrays and Collections.
16 Copyright © 2005, Oracle. All rights reserved. Using JDBC to Access the Database.
15 Copyright © 2005, Oracle. All rights reserved. Container-Managed Relationships (CMRs)
1 Copyright © 2005, Oracle. All rights reserved. Introducing the Java and Oracle Platforms.
7 Copyright © 2005, Oracle. All rights reserved. Creating Classes and Objects.
8 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: JavaServer Pages.
J2EE Overview.
10 Copyright © 2005, Oracle. All rights reserved. Reusing Code with Inheritance and Polymorphism.
15 Copyright © 2005, Oracle. All rights reserved. Adding User Interface Components and Event Handling.
6 Copyright © 2005, Oracle. All rights reserved. Building Applications with Oracle JDeveloper 10g.
17 Copyright © 2005, Oracle. All rights reserved. Deploying Applications by Using Java Web Start.
1 RA I Sub-Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Casablanca, Morocco, 20 – 22 December 2005 Status of observing programmes in RA I.
Exit a Customer Chapter 8. Exit a Customer 8-2 Objectives Perform exit summary process consisting of the following steps: Review service records Close.
Custom Statutory Programs Chapter 3. Customary Statutory Programs and Titles 3-2 Objectives Add Local Statutory Programs Create Customer Application For.
JSP and web applications
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
13 Copyright © 2005, Oracle. All rights reserved. Monitoring and Improving Performance.
Campaign Overview Mailers Mailing Lists
© Paradigm Publishing, Inc Access 2010 Level 1 Unit 1Creating Tables and Queries Chapter 2Creating Relationships between Tables.
Displaying Data from Multiple Tables
Vanderbilt Business Objects Users Group 1 Reporting Techniques & Formatting Beginning & Advanced.
Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to.
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
1 RA III - Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Buenos Aires, Argentina, 25 – 27 October 2006 Status of observing programmes in RA.
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
CONTROL VISION Set-up. Step 1 Step 2 Step 3 Step 5 Step 4.
© 2012 National Heart Foundation of Australia. Slide 2.
Copyright © 2013 by John Wiley & Sons. All rights reserved. HOW TO CREATE LINKED LISTS FROM SCRATCH CHAPTER Slides by Rick Giles 16 Only Linked List Part.
Analyzing Genes and Genomes
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Essential Cell Biology
PSSA Preparation.
Chapter 11 Creating Framed Layouts Principles of Web Design, 4 th Edition.
Essential Cell Biology
Immunobiology: The Immune System in Health & Disease Sixth Edition
Energy Generation in Mitochondria and Chlorplasts
Profile. 1.Open an Internet web browser and type into the web browser address bar. 2.You will see a web page similar to the one on.
South Dakota Library Network MetaLib User Interface South Dakota Library Network 1200 University, Unit 9672 Spearfish, SD © South Dakota.
JSP Standard Tag Library
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
® IBM Software Group © 2007 IBM Corporation JSP Custom Tags
JSTL, XML and XSLT An introduction to JSP Standard Tag Library and XML/XSLT transformation for Web layout.
JSTL Lec Umair©2006, All rights reserved JSTL (ni) Acronym of  JavaServer Pages Standard Tag Library JSTL (like JSP) is a specification, not an.
JSTL The JavaServer Pages Standard Tag Library (JSTL) is a collection of useful JSP tags which encapsulates core functionality common to many JSP applications.
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
14 Copyright © 2004, Oracle. All rights reserved. Enhancing the User Interface.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
17 Copyright © 2004, Oracle. All rights reserved. Integrating J2EE Components.
Knowledge Byte In this section, you will learn about:
Presentation transcript:

9 Copyright © 2005, Oracle. All rights reserved. Modularizing JavaServer Pages Development with Tags

9-2 Copyright © 2005, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: Define a custom tag Use custom tags in a JavaServer Page (JSP) Use the customizable Component Palette for JSP Develop a JSP using the JSP Standard Tag Library (JSTL)

9-3 Copyright © 2005, Oracle. All rights reserved. Custom Tags Custom tags are developed in Java and defined and used with XML syntax. Tags are used in a JSP to reduce or constrain the amount of Java scriptlets in the page. Tags are useful for defining custom actions such as: –Accessing a database –Defining recurring tasks –Sending Collections of tags are grouped into JAR files called Tag Libraries.

9-4 Copyright © 2005, Oracle. All rights reserved. Custom Tag Library Components Custom Tag Libraries contain: One or more tag handler class files –May contain additional supporting classes A tag library descriptor ( taglib.tld ) –XML formatted To use a tag in a JSP, perform the following: 1.Invoke the tag library by using the directive. 2.Call the tag in the content of the JSP. 3.Include the location of the taglib.tld file in the web.xml file.

9-5 Copyright © 2005, Oracle. All rights reserved. Tag Handler: Example import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.*; public class HelloWorldTag extends TagSupport { public int doStartTag() { try { JspWriter out = pageContext.getOut(); out.print("Hello from Custom Tag!!!"); } catch(IOException io) { System.out.println("Error in TagMessage: " + io); } return(SKIP_BODY); } public int doEndTag() { return (SKIP_PAGE); }

9-6 Copyright © 2005, Oracle. All rights reserved. Tag Library Descriptors A tag library descriptor (.tld ) is an XML document that describes one or more tags and their attributes. It contains the following elements: Specifies the class for the individual tag Set to empty, tagdependent, or JSP Documentation regarding the library Identifies the tag library location A default name for the library The JSP specification version for the library The tag librarys version

9-7 Copyright © 2005, Oracle. All rights reserved. Using a Custom Tag The following output is from the HelloWorldTag:

9-8 Copyright © 2005, Oracle. All rights reserved. Tags with Attributes Tags with attributes should include the get() and set() methods for each attribute in the tag handler. The tag library descriptor defines each attribute. Supporting classes can validate attributes. hellotag HelloWorldTag empty custName true

9-9 Copyright © 2005, Oracle. All rights reserved. Creating a Custom Tag in JDeveloper To create a custom tag and a tag library in JDeveloper, perform the following: 1.Create a tag library descriptor from the JavaServer Pages category. 2.Right-click the.tld file in System Navigator and select Add Tag to create a tag handler. 3.Right-click the.java file in System Navigator and select Add Attribute or Add Scripting Variable as necessary. 4.Add the tag library to the component palette.

9-10 Copyright © 2005, Oracle. All rights reserved. Tag Libraries in JDeveloper Tag libraries are viewed in JDeveloper by using the component palette. Select View > Component Palette to enable the palette in the integrated development environment (IDE).

9-11 Copyright © 2005, Oracle. All rights reserved. Registering Tag Libraries To add a tag library to the component palette, perform the following: 1.Select Tools > Configure Palette. 2.Add a new palette page. 3.Name the page for display.

9-12 Copyright © 2005, Oracle. All rights reserved. Registering Tag Libraries 4.Select Tools > Manage Libraries. 5.Add the JAR and TLD files to the list of JSP Tag Libraries.

9-13 Copyright © 2005, Oracle. All rights reserved. Registering Tag Libraries

9-14 Copyright © 2005, Oracle. All rights reserved. Using Tag Insight

9-15 Copyright © 2005, Oracle. All rights reserved. JSP Standard Tag Library (JSTL) The JSP Standard Tag Library (JSTL) was developed under the Java Community Process. It provides a common and standard set of custom tags for: Iteration, conditional processing, and expression language support Parsing and transforming XML documents Formatting and parsing strings, dates, and currencies for internationalization Database access and data manipulation

9-16 Copyright © 2005, Oracle. All rights reserved. Core Tag Library The Core library of JSTL is used for typical JSP actions. Reduces the need for scriptlet tags in a JSP Contains four types of tags: –Generic (sets variables and display results of expressions) –Conditional (makes blocks of code dependent on some criteria) –Iteration (repeats actions on blocks of code) –URL-related (creates URLs for linking or redirection) Use the prefix "c" in the taglib directive:

9-17 Copyright © 2005, Oracle. All rights reserved.

9-18 Copyright © 2005, Oracle. All rights reserved. Utilizing Core Tags Use the and tags within your JSP to display and create variables. The value attribute defines what will be displayed or created as a variable: The value attribute of the tag uses Expression Language (EL). Welcome

9-19 Copyright © 2005, Oracle. All rights reserved. Expression Language JSTL tags can contain Expression Language (EL) within attributes. Expression Language: Is a simpler way of writing an expression in JSPs Accesses object properties and collection elements using dot notation Has access to implicit objects Uses a dollar sign and braces to create an expression: ${expression} Welcome

9-20 Copyright © 2005, Oracle. All rights reserved. Using Iteration Tags Use iteration tags to iterate over blocks of code:

9-21 Copyright © 2005, Oracle. All rights reserved. Using the URL Tags The following three tags exist for working with URLs: : Accesses resources by specifying a URL. It is preferred over the directive, because can: –Access URLs that exist outside the same context as the current pages Web application context –Access a relative URL with a foreign Web application context –Include FTP resources : Handles encoding and rewriting of URLs : Redirects the client request

9-22 Copyright © 2005, Oracle. All rights reserved.

9-23 Copyright © 2005, Oracle. All rights reserved. XML Tag Library The XML tag library is used to parse and transform XML documents. XML tags in JSTL conform to XPath syntax. XML tags include,, and other tags similar to the core tag library, in addition to: – : Parses a specified XML document – : Creates a formatted page from an XML source document by using an XSLT stylesheet – : Sets transformation parameters (nested in ) Use the prefix "x" in the taglib directive:

9-24 Copyright © 2005, Oracle. All rights reserved. SQL Tag Library The SQL Tag Library contains tags for testing database applications. Only used for prototyping or low-volume applications Use the prefix sql in the taglib directive:

9-25 Copyright © 2005, Oracle. All rights reserved. Accessing a Database with SQL Tags To access a database from the SQL tags, you can either: Reference a defined J2EE data source by name in the or tags Or Create a data source by using a tag:

9-26 Copyright © 2005, Oracle. All rights reserved. Querying Using SQL Tags SELECT * FROM customers

9-27 Copyright © 2005, Oracle. All rights reserved. Inserting, Updating, and Deleting Data Use the tag to insert, update, or delete data. For example: UPDATE customers SET account_mgr_id=147 WHERE account_mgr_id=149 Rows Updated.

9-28 Copyright © 2005, Oracle. All rights reserved. Formatting Tags Formatting Tags are used to specify how numbers, dates, and times, should be formatted and parsed in a locale-sensitive manner. It is also called "i18n" tags. Use either java.util.ResourceBundle or java.util.Locale to format data. Use the prefix fmt in the taglib directive:

9-29 Copyright © 2005, Oracle. All rights reserved. Internationalization Concepts There are three main considerations for internationalizing an application: Locale (geographical or political region) Resource bundle (set of paired messages and keys) Basename (identifier for a resource bundle)

9-30 Copyright © 2005, Oracle. All rights reserved. Internationalizing Strings To look up a message in a resource bundle, using the current locale, specify the key attribute in the tag: Alternatively, specify the basename to use with the tag:

9-31 Copyright © 2005, Oracle. All rights reserved. Formatting Numbers and Dates There are several formatting tags for working with numbers and dates, including: : Specify how a percentage, currency, or number should appear using patterns and locales : Specify how a date and/or time should appear using patterns, locales, and time zones

9-32 Copyright © 2005, Oracle. All rights reserved.

9-33 Copyright © 2005, Oracle. All rights reserved. Formatting Numbers and Dates To reverse the formatting that is executed by the format tags, use the following tags: : Parses a number into a currency, percent, or number : Parses a date in a customized or a locale-specific manner –Specify the way the date string should be formatted by using the pattern or parseLocale attributes.

9-34 Copyright © 2005, Oracle. All rights reserved. Transforming XML Documents XML uses XSLT stylesheets to transform data. You can accomplish the same by using the tag:

9-35 Copyright © 2005, Oracle. All rights reserved. JSTL in JDeveloper JDeveloper includes all four libraries of the JSP Standard Tag Libraries in the component palette. The Design editor resolves the output of the tag, as with any other JSP element.

9-36 Copyright © 2005, Oracle. All rights reserved. Summary In this lesson, you should have learned how to: Develop custom tags for use in JSP applications Add custom tag libraries to the Component Palette Use the JSTL custom tag libraries in JSP applications

9-37 Copyright © 2005, Oracle. All rights reserved. Practice 9-1: Overview This practice covers creating a JSP that uses the JSTL custom tag library.

9-38 Copyright © 2005, Oracle. All rights reserved.

9-39 Copyright © 2005, Oracle. All rights reserved.

9-40 Copyright © 2005, Oracle. All rights reserved.