Custom Tags and Implicit Variables

Similar documents
Services. Custom Tag Libraries. Today. Web Development. Role-Based. Development. Code Reuse. Tag Libraries Custom Tags. Tag Lifecycle.

JSP Java Server Pages

BIRT Application and BIRT Report Deployment Functional Specification

Web Applications. Originals of Slides and Source Code for Examples:

Complete Java Web Development

Building Web Applications, Servlets, JSP and JDBC

Java 2 Web Developer Certification Study Guide Natalie Levi

Getting Started with Web Applications

Implementing SQI via SOAP Web-Services

SESM Tag Library. Configuring a Tag Library APPENDIX

Glassfish, JAVA EE, Servlets, JSP, EJB

CS506 Web Design and Development Solved Online Quiz No. 01

Programming on the Web(CSC309F) Tutorial: Servlets && Tomcat TA:Wael Aboelsaadat

Connecting Custom Services to the YAWL Engine. Beta 7 Release

CrownPeak Java Web Hosting. Version 0.20

Ch-03 Web Applications

Exam Prep. Sun Certified Web Component Developer (SCWCD) for J2EE Platform

PowerTier Web Development Tools 4

WIRIS quizzes web services Getting started with PHP and Java

Building and Using Web Services With JDeveloper 11g

SSC - Web applications and development Introduction and Java Servlet (II)

Mastering Tomcat Development

JSP. Common patterns

Spring Security SAML module

Workshop for WebLogic introduces new tools in support of Java EE 5.0 standards. The support for Java EE5 includes the following technologies:

Web Application Architecture (based J2EE 1.4 Tutorial)

Java Web Programming. Student Workbook

Web Applications. For live Java training, please see training courses at

Running and Testing Java EE Applications in Embedded Mode with JupEEter Framework

Developing Web Applications using JavaServer Pages and Servlets

Oracle WebLogic Server

Topics. Incorporating JSP Custom Tags Into Your Web Apps. A Quick Example of Using One. What They Are. Why Developers Should Consider Them

Install guide for Websphere 7.0

WebSphere v5 Administration, Network Deployment Edition

Enterprise Applications

Java 2 Web Developer Certification Study Guide Natalie Levi; Philip Heller

TIBCO Runtime Agent Authentication API User s Guide. Software Release November 2012

Java Servlet 3.0. Rajiv Mordani Spec Lead

WEB-BASED DATABASE ACCESS: A PEDAGOGICAL STRATEGY

Getting Started with the Internet Communications Engine

Server-Side Web Development JSP. Today. Web Servers. Static HTML Directives. Actions Comments Tag Libraries Implicit Objects. Apache.

ServletExec TM 5.0 User Guide

Web Service Caching Using Command Cache

Introduction to J2EE Web Technologies

Web Container Components Servlet JSP Tag Libraries

INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011

Development. with NetBeans 5.0. A Quick Start in Basic Web and Struts Applications. Geertjan Wielenga

Java Interview Questions and Answers

Web Applications and Struts 2

opencrx Language Localization Guide

Server Setup and Configuration

Oracle WebLogic Server

A Sample OFBiz application implementing remote access via RMI and SOAP Table of contents

Oracle Forms Services Secure Web.Show_Document() calls to Oracle Reports

Model-View-Controller. and. Struts 2

Volume 1: Core Technologies Marty Hall Larry Brown. An Overview of Servlet & JSP Technology

A Guide to Understanding Web Application Development Corey Benson, SAS Institute, Inc., Cary, NC Robert Girardin, SAS Institute, Inc.

Java 7 Recipes. Freddy Guime. vk» (,\['«** g!p#« Carl Dea. Josh Juneau. John O'Conner

Web development... the server side (of the force)

JBoss Portlet Container. User Guide. Release 2.0

Course Name: Course in JSP Course Code: P5

The end. Carl Nettelblad

TIBCO ActiveMatrix BPM Web Application Component Development. Software Release 2.0 November 2012

Web Application Developer s Guide

Oracle WebLogic Server

Alkacon Software GmbH

Creating Java EE Applications and Servlets with IntelliJ IDEA

HP OpenView Service Desk Version 3.0

Web Programming II JSP (Java Server Pages) ASP request processing. The Problem. The Problem. Enterprise Application Development using J2EE

Controlling Web Application Behavior

JBoss SOAP Web Services User Guide. Version: M5

Hello World Portlet Rendered with JSP for WebSphere Portal Version 4.1

Tutorial: Building a Web Application with Struts

Creating a Java application using Perfect Developer and the Java Develo...

Creating Custom Web Pages for cagrid Services

EVALUATION. WA1844 WebSphere Process Server 7.0 Programming Using WebSphere Integration COPY. Developer

Module 13 Implementing Java EE Web Services with JAX-WS

AP Computer Science Java Subset

Django Assess Managed Nicely Documentation

Web Development in Java

Sonatype CLM Enforcement Points - Continuous Integration (CI) Sonatype CLM Enforcement Points - Continuous Integration (CI)

Servlet 3.0. Alexis Moussine-Pouchkine. mercredi 13 avril 2011

Java Platform, Enterprise Edition (Java EE) From Yes-M Systems LLC Length: Approx 3 weeks/30 hours Audience: Students with experience in Java SE

CRM Setup Factory Installer V 3.0 Developers Guide

Oracle Forms Services Secure Web.Show_Document() calls to Oracle Reports Server 6i

How to Write AllSeen Alliance Self- Certification Test Cases September 25, 2014

Crystal Reports for Borland JBuilder

Chapter 22: Integrating Flex applications with portal servers

Web Frameworks and WebWork

Development_Setting. Step I: Create an Android Project

JAX-WS Developer's Guide

CREATE A CUSTOM THEME WEBSPHERE PORTAL

Improve application performance and scalability with Adobe ColdFusion 9

Glossary of Object Oriented Terms

Exception Handling In Web Development DevelopIntelligence LLC

Oracle8/ SQLJ Programming

NetBeans IDE Field Guide

Deploying Microsoft Operations Manager with the BIG-IP system and icontrol

Magento Search Extension TECHNICAL DOCUMENTATION

InfoSphere Master Data Management operational server v11.x OSGi best practices and troubleshooting guide

Transcription:

Custom Tags and Implicit Variables 1. List down the essential steps to writing a custom tag for use in your JavaServerPages? a. Writing a Java class called a tag handler b. Defining the tag within a tag library definition (TLD) file c. Providing details of where to find the TLD file in the deployment descriptor, web.xml d. Referencing the TLD file in your JSP page source and using the tags from it 2. Formerly without EL and JSTL you would always have to write your own. (Or acquire some from a third party) to avoid Java scripting. a. custom tags 3. List down the four artifacts involved with a custom tag? a. A Java class file, a TLD file, web.xml, and the JSP page itself. 4. Will the tag handler code have access to the JSP implicit variables? a. The tag handler classes don t. What they have instead is a PageContext object. We can use methods on this object to get hold of the implicit variable equivalents. 5. The pagecontext implicit object of JSP is of type.. a. javax.servlet.jsp.pagecontext 6. Can we create objects of javax.servlet.jsp.pagecontext and use it instead of pagecontext implicit object? a. This is an abstract class. JSP container provides an instance of a subclass that has implemented all the abstract methods it contains. 7. How will you get the PageContext object in the tag handler code? a. The PageContext object is passed in the setpagecontext() method. If your tag class inherits from TagSupport (or BodyTagSupport), setpagecontext() saves the object to a protected instance variable so that you can access it directly in your code as pagecontext. 8. How can you obtain different JSP implicit objects from the PageContext object? a. request i. getrequest() b. response ii. getresponse() 1

c. out iii. getout() (inherited from PageContext s parent class JspWriter) d. session iv. getsession() e. config v. getservletconfig() f. application vi. getservletcontext() g. page vii. getpage() h. pagecontext viii. This is the PageContext object passed to your tag handler i. exception ix. getexception() 9. An implicit variable that isn t necessarily always available is. a. exception 10. When will the implicit variable exception available within a tag handler class? a. The exception implicit variable is available only in a JSP error page. When another page specifies your error page and when that other page goes wrong, he exception produced by the other page is then available to your error page, as the implicit variable exception in the JSP source. If that JSP source has a custom tag within it, that custom tag can invoke pagecontext.getexception() and expect an Exception object back. Under other circumstances, the call will return null. 11. How is a Simple Custom Tag Event Model different from a classic tag event model? a. Instead of three life cycle choices based on the interfaces Tag, IterationTag, and BodyTag for a classic tag event model, you have only one for a Simple Custom Tag Event Model, which is based on the javax.servlet.jsp.tagext.simpletag interface. 2

b. The dotag() method replaces all of dostarttag(), doafterbody(), and doendtag().all the processing that would have occurred in those methods moves to dotag(). Furthermore, dotag() returns nothing at all. c. With simple tags, you don t use return codes (such as Tag.SKIP_BODY) to influence the life cycle. The life cycle as it directly affects the tag output is controlled instead by your code inside dotag(). d. Unlike classic model tags you get a new instance for every use of Simple tags. So you can safely initialize variables in your constructor or instance member declarations. There is no pool for simple tags. e. In classic model, if the container decides to take a particular instance of a tag out of service, then release() is called, which you can use to clean up any expensive resources associated with the tag. There is no release() method for simple tags. So any cleanup must happen in dotag() (or a method called from dotag()). f. In the simple tag file declaration within the TLD, the <body-content> is restricted to three allowed values: empty, tag dependent, and scriptless instead of four for custom model which also includes JSP. 12. What will happen if an attribute declared as mandatory in the TLD for a custom tag is missing from its use in the JSP? Need to find. 13. What will happen if an attribute declared as mandatory in the TLD for a custom tag is not having a corresponding setter in the tag handler? Need to find. 14. What are dynamic attributes? a. Attributes which can be added individually on a per tag and per JSP author basis are known as dynamic attributes. 15. How can a tag handler support dynamic attributes? a. A tag handler that supports dynamic attributes must implement the javax.servlet.jsp.tagext.dynamicattributes interface implementing the setdynamicattribute() method: i. void setdynamicattribute(string ns, String name, Object value) Container calls this to set the name and value of the attribute along with any preceding namespace qualifier. If qualifier is not given the attribute is assumed to be in the default namespace and ns will be null. 3

b. Additionally it must be configured in the TLD that this tag handler can accept dynamic attributes. i. <tag> ii. <name>mytag1</name> iii. <tag-class>tags.tag1</tag-class> iv. <body-content>empty</body-content> v. <dynamic-attributes>true</dynamic-attributes> vi. </tag> 16. What is variable synchronization? a. Variable synchronization is a mechanism through which container will update a variable in the JSP or the generated servlet to follow the value of a scoped attribute. Underneath it is always the scoped attribute which is modified by the tag. The synchronization causes the container to copy the value of the scoped attribute into the scripting variable, conveniently integrating JSP scripting elements with the tag. b. TLD is the primary location used to configure scripting variables and synchronization details. Tag files use the tag directive to specify the variables they expose. c. To declare synchronization in TLD we use the <variable> element in the TLD. Possible values are AT_BEGIN, NESTED, AT_END which is the scope of the scripting variable within the page. i. AT_BEGIN variables are created in the servlet code before the action is invoked and synchronized throughout the tags life cycle and remain in existence after the tag completes processing. ii. NESTED variables are created before the action is invoked and removed when the action terminates. iii. AT_END variables are created just after the tag finishes its invocation. d. Both classic and simple tags can expose variables for synchronization, but only classic tags can make use of them in their bodies as simple tags and JspFragment cannot contain JSP scripting. 4

17. During variable synchronization, will the container always declare the variables for synchronization? How can we change that behavior? a. During variable synchronization, the container will declare the variables for synchronization. However we can tell the container to re-initialize but not redeclare the variable by using a value of false for the <declare> element in the TLD. b. When using a value of false for the <declare> element for an attribute in the TLD, we should make sure that the variable already exist and if it doesn t exist, translation will fail. 18. If the container encounters an attribute which does not recognize for an action, what will it do first? a. It will first check the action s dynamic attribute setting in the TLD. i. If the action is configured to accept dynamic attributes, the JSP will translate and compile fine. ii. If the action cannot accept dynamic attributes, a validation error will occur. 19. Describe argument fragments? a. A JSP fragment is a portion of JSP code passed to a tag handler that can be invoked as many times as needed. A fragment can be considered as a template that is used by a tag handler to produce customized content. Unlike a simple attribute which is evaluated by the container, a fragment attribute is evaluated by a tag handler during tag invocation. b. Attributes may be configured in the TLD as attribute fragments so that they are converted into JSP fragments which can be invoked to process their contents, rather than any other regular object type. To declare an attribute as fragment attribute, we can use <fragment>true</fragment> in the TLD for that attribute. c. If you want to present an attribute as JspFragment to a tag, we will need to supply the attribute as a <jsp:attribute> child and not as a normal attribute. d. The JspTag handler for tags with fragment attributes requires a JavaBean setter method for each fragment attribute, just as for any other fixed attribute the tag 5

takes. The parameter to the setter method must be of type javax.servlet.jsp.tagext.jspfragment. 20. How does JSTL tags provide synchronization? a. JSTL tags do not provide synchronization forcing us to either do the synchronization ourselves or use EL. 21. Can a single JAR contain more than one tag library? a. A single JAR may contain more than one tag library each identified by a unique TLD. 22. Should a TLD accompany all tag handler classes and tag files within a JAR? What will happen if we have tag handler classes or tag files without a TLD? a. A TLD must accompany all tag handler classes and tag files within a JAR. Each TLD should be deployed into the META-INF directory or any subdirectory. Any tags or tag files not declared in the TLD will not be recognized or loaded by the container. 23. Is it valid for an explicit and implicit TLD to reference the same tag file? a. Yes 24. What is an implicit TLD? a. All tag files deployed directly into a WAR should be placed in the WEB-INF/tags or a subdirectory of it. Tag files deployed in the WEB-INF/tags or subdirectories of it are assigned an implicit TLD by the container. This implicit TLD is created by the container as and when required. An implicit TLD is created by the container for each subdirectory and each subdirectory therefore represents a different tag library. 25. Can we have a TLD created manually for a tag file? a. They need not have a TLD even though we can provide one. 26. How can we create implicit TLDs for our tag handler classes? a. Implicit TLDs will be created only for tag files, not tag handler classes. When deploying tag handler classes directly into the application, all tags must have an accompanying TLD inside WEB-INF or a subdirectory of it. 27. How are custom tags different from custom actions? 6

a. They are both the same. Custom tags are also known as tag extensions or custom actions. 28. What are tag handlers? a. The actual classes which implement and define the behavior of both classic tags and tag files are known as tag handlers. However in case of tag files, the tag handler class is created by the container during tag files translation and classic tag handlers should be programmed directly. 29. How is standard action s handler different from JSTL or custom action s handler? a. Unlike JSTL or custom actions, standard actions are optimized by the container and embedded directly into the translated servlet code, without using separate handler instances. 30. When packaging tag files into tag library JARs, where should the tag handler classes and tag files be present? a. When packaging tag files into tag library JARs, all tag handler classes are packaged into the JAR under a path which maps to their package names. All tag files must be placed in, or in any sub-directory of the META-INF/tags directory in the JAR. Tag files which are precompiled into tag handler classes are deployed like other tag handler classes. 31. The setxxx methods for each attribute xxx on the tag handler called before or after the dostarttag() or dotag() methods for custom tags and simple tags respectively? a. The container will call the setxxx methods for each attribute xxx on the tag handler always before the dostarttag() or dotag(). 32. More Notes a. When considering tag handlers, attributes can be considered to be the JavaBean s properties. b. The tag handler can be almost considered as a JavaBean and should have atleast setters for these attributes. 7