12001-03-28Enterprise Java: Developing JSP Custom Tag Libraries Developing JSP Custom Tag Libraries O'Reilly Conference on Enterprise Java, March 2001.

Slides:



Advertisements
Similar presentations
Servlets & JSPs - Sharad Ballepu.
Advertisements

J0 1 Marco Ronchetti - Basi di Dati Web e Distribuite – Laurea Specialitica in Informatica – Università di Trento.
JSP Custom Tags Keyton Weissinger Key Focus, Inc. 27 March 2001 OReilly Conference on Enterprise Java Santa Clara, CA.
9 Copyright © 2005, Oracle. All rights reserved. Modularizing JavaServer Pages Development with Tags.
8 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: JavaServer Pages.
JSP and Servelets.
JSP and web applications
Creating Custom JSP Tag Libraries Taken from Core Servlets and JavaServer Pages from Prentice.
Page 12001/02/15Thomas MickleyRecipe Database and Management jw Central Recipe Database and Management MSc Thomas Mickley consulting
CS4273: Distributed System Technologies and Programming I Lecture 11: JavaServer Pages (JSP)
Apache Struts Technology
© Yaron Kanza Advanced Java Server Pages Written by Dr. Yaron Kanza, Edited by permission from author by Liron Blecher.
Java II--Copyright © Tom Hunter. J2EE JSP Custom Tag Libraries.
Advanced Java Server Pages An more detailed look at JSPs.
JSP Tag Extensions And Java Bean. JSP Tag Extensions Tag extensions look like HTML (or rather, XML) tags embedded in a JSP page. They have a special meaning.
DT211/3 Internet Application Development
Generate Dynamic Content On Cache Server Master’s Project Proposal by Aparna Yeddula.
Object-Oriented Enterprise Application Development JavaServer Pages Tag Libraries.
JSP Architecture  JSP is a simple text file consisting of HTML or XML content along with JSP elements  JSP packages define the interface for the compiled.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
Java Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 9 JavaServer Pages (JSP) (Based on Møller.
Java for the WWW November 2012Slide Tag Libraries What are they? –Custom libraries Custom tags – see examples in following slides.
Java Beans.
OOSSE - OO Review Review session A review of other OO technologies and may be useful for exam (not required for assignment) OO web development philosophy.
Basic Elements JSP For a Tutorial, see:
CSC 2720 Building Web Applications Using Java Beans, Custom Tags and Tag Libraries in JSP pages.
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.
Chapter 111© copyright Janson Industries 2011 Custom Tags ▮ Tag Handlers ▮ XML ▮ Tag Libraries ▮ Web Deployment Descriptor.
® IBM Software Group © 2007 IBM Corporation JSP Custom Tags
Introduction to Java Server Pages (JSPs) Robert Thornton.
1 JSP 1.2 Custom Tags. 2 Agenda ● What is and why custom tags? ● Components that make up custom tag architecture ● How to create custom tags? ● How does.
Custom Tags1 Usage Rules PowerPoint slides for use only in for-credit courses at degree-granting institutions Slides can be modified.
Chapter 7 Java Server Pages. Objectives Explain how the separation of concerns principle applies to JSP Describe the operation and life-cycle of a JSP.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
Java Server Pages Lecture July Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java)
Jordan Anastasiade. All rights reserved.
® IBM Software Group © 2007 IBM Corporation JSP Expression Language
Stanisław Osiński, 2002JSP – A technology for serving dynamic web content Java Server Pages™ A technology for serving dynamic web content Stanisław Osiński,
JAVA SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
Fall CIS 764 Database Systems Design L8. Web ….
1 JSP with Custom Tags Blake Adams Introduction Advanced Java Server Pages – Custom Tags Keyterms: - Tag Library Descriptor(TLD) - Tag Libraries.
JSTL Lec Umair©2006, All rights reserved JSTL (ni) Acronym of  JavaServer Pages Standard Tag Library JSTL (like JSP) is a specification, not an.
Fall 2007cs4201 Advanced Java Programming Umar Kalim Dept. of Communication Systems Engineering
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
CSC 2720 Building Web Applications JavaServer Pages (JSP) The Basics.
JSP Tag Libraries Lec Last Lecture Example We incorporated JavaBeans in “Course Outline” Example But still have to write java code inside java.jsp.
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
Java Server Pages (JSP)
Java Server Pages An introduction to JSP. Containers and Components Several clients – one system.
JavaServer Page by Antonio Ko. Overview ► Introduction ► What is a servlet? ► What can servlets do? ► Servlets Vs JSP ► Syntax ► Samples ► JavaBean ►
JSP Custom Tags. Prerequisites Servlet API Mapping to JSP implicit objects JavaServer Pages Basic syntax Implementation via servlet API XML.
JSP Pages. What and Why of JSP? JSP = Java code imbedded in HTML or XML –Static portion of the page is HTML –Dynamic portion is Java Easy way to develop.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
Advanced Java Session 6 New York University School of Continuing and Professional Studies.
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
Java Web 应用开发: J2EE 和 Tomcat 蔡 剑, Ph.D.. 本讲内容 Web 层技术 (III) Custom Tags JSP and XML JSTL.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
® IBM Software Group © 2007 IBM Corporation JSP Tag Files
J2EE JSP Custom Tag Libraries 1 3 JSP: Custom Tag Libraries.
JSP: Actions elements and JSTL
Developing JavaServer Pages
Knowledge Byte In this section, you will learn about:
Pre-assessment Questions
MSIS 655 Advanced Business Applications Programming
JavaServer Faces: The Fundamentals
JSP Revisited Instructors: Geoffrey Fox and Bryan Carpenter
JSP Custom Tags Welcome.
Presentation transcript:

Enterprise Java: Developing JSP Custom Tag Libraries Developing JSP Custom Tag Libraries O'Reilly Conference on Enterprise Java, March 2001

Enterprise Java: Developing JSP Custom Tag Libraries Who I Am Hans Bergsten –President of Gefion software –Member of the JSP working group (JCP) – Author of JavaServer Pages (OReilly)

Enterprise Java: Developing JSP Custom Tag Libraries Overview The JSP promise Custom Action Main Components Implementation Examples New in JSP 1.2 Not a JSP introduction! Plenty of Code!

Enterprise Java: Developing JSP Custom Tag Libraries Before JSP public void doGet(…) { ResultSet rs = getCustomers(VIP); out.println( ); while (rs.next()) { out.println( + rs.getString(Name); }

Enterprise Java: Developing JSP Custom Tag Libraries With JSP 1.0 <% ResultSet rs = cdb.getCustomers(VIP); %>

Enterprise Java: Developing JSP Custom Tag Libraries With JSP 1.1 Custom Actions <jsp:getProperty name=cust property=name />

Enterprise Java: Developing JSP Custom Tag Libraries Types of Custom Actions JSP for all MVC roles –Database access –EJB access –Input Validation JSP just as View –Presentation –Conditional processing

Enterprise Java: Developing JSP Custom Tag Libraries Custom Action Representation <foo:loop name=vips loopId=cust> … or <foo:getVIPCust id=vips /> XML element –Opening tag –Body –Closing tag –Shorthand notation for element without a body

Enterprise Java: Developing JSP Custom Tag Libraries Custom Action Components Tag handler class Tag Library Descriptor (TLD) TagExtraInfo subclass

Enterprise Java: Developing JSP Custom Tag Libraries Basic Tag Handler XXX implements Tag { setPageContext(…) setParam(...) setValue(…) doStartTag() doEndTag() <foo:ifEq param=sale value=true> On Sale!

Enterprise Java: Developing JSP Custom Tag Libraries Implementing the IfEqTag public class IfEqTag extends TagSupport { … public int doStartTag() { ServletRequest req = pageContext.getRequest(); String paramValue = req.getParameter(param); if (value.equals(paramValue)) { return EVAL_BODY_INCLUDE; else { return SKIP_BODY; } }

Enterprise Java: Developing JSP Custom Tag Libraries Tag Library Descriptor (TLD) … ifEq com.foo.IfEqTag JSP

Enterprise Java: Developing JSP Custom Tag Libraries Tag Library Descriptor (TLD), Contd param true

Enterprise Java: Developing JSP Custom Tag Libraries JSP taglib Directive On Sale!

Enterprise Java: Developing JSP Custom Tag Libraries How It All Fits Together On Sale! TLD ifEq XXX Tag handler

Enterprise Java: Developing JSP Custom Tag Libraries Basic Tag Handler Examples Conditional processing: –doStartTag() -> EVAL_BODY_INCLUDE, SKIP_BODY –doEndTag() -> EVAL_PAGE, SKIP_PAGE Presentation: i18n, complex tables, etc. Data access: database, EJB, etc.

Enterprise Java: Developing JSP Custom Tag Libraries Processing the Element Body Dear... XXX impl. BodyTag { setPageContext(…) setTo(...) doStartTag() setBodyContent(...) doInitBody() doAfterBody() doEndTag()

Enterprise Java: Developing JSP Custom Tag Libraries Buffering Hierarchy Some text Dear JspWriter BodyContent

Enterprise Java: Developing JSP Custom Tag Libraries BodyContent class JspWriter subclass, buffers the element body evaluation result for BodyTags –getReader() –getString() –writeOut(java.io.Writer out) –getEnclosingWriter()

Enterprise Java: Developing JSP Custom Tag Libraries Implementing the MailTag public class MailTag extends BodyTagSupport { … public int doAfterBody() { mailBean.setTo(to); mailBean.setMsg(getBodyContent().getString()); mailBean.deliver(); return SKIP_BODY; } }

Enterprise Java: Developing JSP Custom Tag Libraries BodyTag Handler Examples Iterations –doAfterBody() -> EVAL_BODY_TAG, SKIP_BODY Dynamic input, using other JSP elements to create it Static input spanning multiple lines, e.g. SQL, XML, other non-JSP syntax.

Enterprise Java: Developing JSP Custom Tag Libraries Validating Element Syntax Two mechanisms: –Container validation using the TLD: param true –Use a TagExtraInfo class with isValid() Can be combined

Enterprise Java: Developing JSP Custom Tag Libraries Validation with TagExtraInfo public class MailTEI extends TagExtraInfo { public boolean isValid(TagData data) { if (data.getAttribute(to) != null && data.getAttribute(toList) != null) { return false; // Mutually exclusive optional } if (data.getAttribute(name) != null && data.getAttribute(property) == null) { return false; // Dependent optional } return true;

Enterprise Java: Developing JSP Custom Tag Libraries Letting Actions Cooperate Through objects in a JSP scope: Through direct method calls on the parent tag handler:

Enterprise Java: Developing JSP Custom Tag Libraries Coop Through Objects Save the object in one tag handler: public int doXXX() {... pageContext.setAttribute(id, value, scope); } Get the object in another tag handler: public int doXXX() { … Object o = pageContext.findAttribute(name); }

Enterprise Java: Developing JSP Custom Tag Libraries Scripting Variable Assignment public class GetVIPCustTEI extends TagExtraInfo { public VariableInfo[] getVariableInfo(TagData data) { VariableInfo vi = new VariableInfo[1]; vi[0] = new VariableInfo( data.getAttributeString(id), // Variable name com.mycomp.CustBean, // Variable type true, // Declare variable? VariableInfo.AT_END); // Assignment scope return vi; } }

Enterprise Java: Developing JSP Custom Tag Libraries Coop Through Method Calls public class ParamTag extends TagSupport { public int doEndTag() { RedirectTag parent = (RedirectTag) findAncestorWithClass(this, RedirectTag.class); if (parent != null) { parent.setParam(name, URLEncoder.encode(value); } return EVAL_PAGE; } }

Enterprise Java: Developing JSP Custom Tag Libraries JSP 1.2 Tag Library News New Interfaces –IteratorTag, TryCatchFinally Validation Enhancements –TagLibraryValidator class, TEI isValid() Application & session event listeners TLD can describe tag handler variables

Enterprise Java: Developing JSP Custom Tag Libraries More Info JSP Specification JavaServer Pages book Jakarta Taglibs & Struts InstantOnline Basic