230 likes | 244 Views
Learn JavaServer Pages (JSP) fundamentals, including creating data-centric JSPs using ADF data binding, incorporating HTML, Struts, JSTL tags, and custom elements. Utilize IDE features in JDeveloper for effective JSP development. Understand custom tags, tag libraries, and data binding techniques.
E N D
Objectives • After completing this lesson, you should be able to do the following: • Describe how a JSP works • Describe the fundamental components of a JSP • Create a JSP • Include components into JSP (HTML, Struts, and JSTL tags) • Create a data-centric JSP using ADF data binding
What Is a JSP? • JavaServer Pages are aJ2EE component, which: • Is a “View” in the ADF MVC structure • Contains presentation logic • Mixes HTML, Java, and XML in a page • Enables Web developers to create applications that focus on the “look and feel” of an application • Is based on the servlet architecture • Supports the use of custom tags and beans to incorporate presentation logic
JavaServer Pages in ADF Calls Request Client JSP Struts Generates Controls Dynamic content ADF Business Components Response
Example: JSP <%@ page contentType="text/html;charset=WINDOWS-1252"%> <html> <head> <title> Show Date </title> </head> <body> <h2> The current time is: </h2> <p> <%= new java.util.Date() %> </p> </body> </html>
Element • Syntax • Purpose • Scriptlets • <% if(x == null) { %> • Hello! <% } %> • Java code • Expressions <%= "a" + "b" %> • Java code that is evaluated • Directives <%@ page language="java" %> • Global values • Declarations <%! private int hitCount = 0; %> • Variable declarations Basic JSP Elements • A JSP can contain HTML text and four main elements:
JSP Directives • There are three types of JSP directives: • page • include • taglib <%@ page contentType="text/html;charset=WINDOWS-1252"%> <%@ include file="signature.html" %> • <%@ taglib uri="webapp/taglib.tld" prefix="mytags" %> <html> <body> <h2> The current time is: </h2> <p> <%= new java.util.Date() %> </p> </body> </html>
JDeveloper and JSPs • JDeveloper contains several IDE features to simplify JSP development: • Visual Editor (WYSIWYG) • Component Palette • Many Custom Tag libraries are included, including: • JSP Standard Tag Library (JSTL) • Apache Struts • Oracle JSP • ADF Data Tags
The Visual Editor • Provides direct editing of: • Text • HTML elements • Data controls • The toolbar contains formatting tools for: • Color • Text size • Format (style) • You can drag CSS definitions to a page
What Are 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 recurring tasks such as accessing a database or sending an e-mail. • Custom tags are packaged into libraries: • Packaged as .jar files • Defined in a .tld file
Utilizing Tag Libraries • Tag libraries are utilized in a JSP by: • Defining the location of the tag library using the taglib directive • Creating a prefix to reference the tag library in the JSP • Using the prefix to call a tag and specifying attributes as necessary <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%> <c:out value="avalue"></c:out>
JSP Standard Tag Library • The JSP Standard Tag Library (JSTL) is being 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
Struts Tags • The Apache Struts technology containsa custom tag library for use with JSPs. • There are several categories of Strutslibraries available in the ComponentPalette, including: • Struts HTML • Logic • Struts Beans • Templates • Nested • Tiles
Data Binding Tags • The Data Control Palette contains objects that are mapped to the workspace’s business components. The controls may be included in the JSP in different formats, depending on the type of model component they represent: • Input Text (Individual Item) • Input Form (Complete View Object) • Button (Operation such as Commit)
Utilizing the Data Control Palette • Drag components fromthe Data Control Paletteto the Visual Editor of aJSP to display data. • Use the Drop Aslist box to select thestyle of the control.
How Data Is Displayed • JSTL is used to iterate through and display data: • <c:out value="${expr}" /> • <c:forEach var="Row" >…</c:forEach> <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%> <table border="1" width="100%"><tr> <c:forEach var="Row" items="${bindings.OrdersView1.rangeSet}"> <tr><td> <c:out value="${Row.currencyString}"> </c:out> </td>…
View Object Control Types • Use view object component types to display all data in a view object. Drop the view object as one of the following types of controls: • Table • Dynamic Table • Navigation Buttons • Input Form • Read-Only Form • Select Row Link • Graph • Navigation List
View Object Item Control Types • To display a data control that represents a single view object item, select the item in the Data Control Palette and add it to the JSP as a: • Value • Label • Input Field • Password Field
Operations • Operations are data actions that interact with an entire view object or an entire application module. They include: • Create: Creates a new row in the view object • Find: Navigate to a specific row in the view object • Delete: Deletes the current row • Execute: Submit a query • Navigation sets (First Set, Last Set, First, and Next) • Commit: Commits an entire application module • Rollback: Rolls back changes on an application module
Customizing Controls • Select View > Property Inspector to modify the control properties. • For operations, you may also double-click the button to modify the name and value.
JSP Versus UIX • An ADF view can also be created as a UIX page: • More visual components are available in UIX. • The Data Control Palette can be used to create data-bound UIX pages.
Summary • In this lesson, you should have learned how to: • Create JSP pages that use scriptlets, expressions, and declarations to generate dynamic content • Incorporate tag libraries in JSP pages to further the component-centric design of JSP applications • Add ADF Business Components to a JSP via the Data Control Palette
Practice 10-1: Overview • This practice covers the following topics: • Creating a JSP for user login • Creating navigation to another JSP • Creating a JSP for editing and inserting customer data