Oracle Specific Features

Oracle has provided developers with additional features that extend the functionality of JSPs and how they are processed by the Oracle Application Server 10g engine. These features are discussed in the next couple of sections.

Extended Type JavaBeans

The first feature we will discuss is the JavaBean-based extended types that are available. Storing primitive data types such as int, boolean, and float in the various JSP scopes is not allowed, and the standard Java wrapper classes do not comply with the JavaBeans API specification. Oracle s solution to this problem is a set of classes that act as JavaBean-compliant wrappers for the primitive data types. The oracle.jsp.jml package contains a set of classes that allow you to store representations of the primitive data types using the standard <jsp:useBean/> tag. Table 14-5 maps the available extended types to Java s primitive types.

Table 14-5: Oracle-Java Primitive-Type Mapping

Oracle Extended Type JavaBean

Java Type

oracle.jsp.jml.JmlBoolean

boolean

oracle.jsp.jml.JmlFPNumber

double

oracle.jsp.jml.JmlNumber

int

oracle.jsp.jml.JmlString

String

The JSP Expression Language and the Java Standard Tag Libraries will be covered in detail later in this chapter in the section Java Standard Tag Libraries.

In addition to the getValue method, there are several other methods that allow for comparison to other types. The getTypedValue( ) and setTypedValue( ) methods are overloaded to allow comparison and setting to or from a String, boolean, or JmlBoolean. These methods will generally be used in Java classes for comparison and initialization of the Java bean.

The JmlFPNumber and JmlNumber classes are used to represent integer and floating-point values, respectively. These classes also use the value attribute setter method to initialize the value when used inside a JSP. Using these classes can cause your JSP to throw java.lang.NumberFomatException if the value cannot be converted to a number. The JmlString class is a wrapper for the java.lang.String class that is mutable and has a very handy isEmpty() method that returns false if the object contains an empty String ( ). You can also compare JmlString objects to each other by using the overloaded .equals(JmlString) method.

Since most primitive data types are properties of objects and wrapped inside of JavaBeans, these classes are only useful if you do not have to model complex objects and simply need to store a single value. One advantage to using these classes is that the objects are mutable, unlike their java.lang counterparts.

JSP Markup Language (JML)

Oracle provides a set of custom tags that allows developers with little or no knowledge of Java to create JavaServer Pages. JSP Markup Language (JML) provides tags for conditional logic, database access, looping, and other useful elements. JML was introduced before the Java Standard Tag Libraries (JSTL) and contains many of the same features. If you are developing a new application, it is recommended that you use JSTL. There is, however, some functionality that JML has that JSTL does not. Table 14-6 lists the available tags, their purpose, and the equivalent JSTL or JSP tag.

Table 14-6: JML/JSTL Comparison

JML Tag Name

Purpose

JSTL/JSP Equivalent

useVariable

Declares simple variables in one of the JSP scopes.

jsp:useBean

useForm

Declares variables and uses the request parameters to set them.

jsp:useBean and jsp:setProperty

useCookie

Declares variables that are initialized from cookies.

 

remove

Removes attributes from various scopes.

session.remove
Value( Name )

If

Evaluates a single expression and executes the code in the body if the condition evaluates to true.

c:if

ChooseWhenotherwise

A multiple conditional statement similar to the standard if-else.

c:choose, c:when, c:if

For

Provides the ability to iterate through a loop.

c:for

foreach

Allows for iterating over Java arrays, Enumerations, and Vectors.

c:forEach

return

Stops page execution at the point it is encountered .

 

Flush

Flushes the page buffer if page buffering is enabled.

 

In addition to JML basic tags, Oracle provides a set of Data-Access JavaBeans and SQL tags for data access. These provide a JSP developer with access to the database from within the JSPs. In simple applications, these components can be used to create dynamic data-driven pages. For medium to complex applications, you should use Oracle s Application Development Framework (ADF).

Note  

See Chapter 13 for more on ADF.

Data-Access JavaBeans provide a set of reusable components that a developer can use to create database connections through a data source or a simple JDBC connection, run SQL queries, execute DML, and run stored procedures. The four JavaBeans available to the developer are contained in the oracle.jsp.dbutil package. To access this package, you must have the ojsputil.jar file in your classpath. This file is provided with the OC4J container.

Connecting to the database can be accomplished by the ConnBean, ConnCacheBean, or the DBBean. The ConnCacheBean provides connection pooling and uses datasources; the DBBean has its own connection mechanism. Using a data source is usually your best bet for scalability and maintainability. For more information on using these beans, see the Oracle Application Server 10 g documentation. You will find descriptions of the tags and their interfaces in Chapter 4, Data-Access JavaBeans and Tags, of the Oracle Application Server Containers for J2EE JSP Tag Libraries and Utilities Reference 10g (9.0.4), Part Number B10319-01 (http://download-west.oracle.com/docs/cd/B10464_01/web.904/b10319/toc.htm).

Oracle Global Includes

Oracle Application Server 10 g provides the ability to do global includes in your JSPs. This feature allows you statically include modules in your JSPs. You can use this feature to add headers or footers to your JSPs without having to code the include directives in every JSP. This feature is accomplished through an XML configuration file located in your applications WEB-INF directory. The ojsp-global-include.xml allows you to specify what, when, and how the include directives should be used. The root element <ojsp-global-include> has one subelement: include. The <include> element s attributes tell the JSP translator what to include and where in the page to include it. You can specify if the include should be at the top of the page (the default) or the bottom. The <include> element, in turn , has one subelement, <into>, that lets you specify what JSPs should process the global includes. You can specify a JSP by directory and, optionally , its subdirectories. For more information and examples on using global includes, see the Oracle Application Server 10 g documentation, http://download-west.oracle.com/docs/cd/B10464_01/web.904/b10320/toc.htm).

Edge Side Includes

Oracle Application Server 10 g provides the ability to break a JSP up into cacheable components by using the Java Edge-Side Includes (JESI) tag library. JESI not only can cache static content but also dynamic content as well. Using JESI can reduce the load on your application server by caching static and dynamic content utilizing Oracle Application Server Web Cache. While learning the ESI framework that JESI is layered on is complex, it is well worth the effort. For a detailed description of Oracle s implementation of JESI, see Oracle Application Server Containers for J2EE JSP Tag Libraries and Utilities Reference 10g (9.0.4) Part Number B10319-01 (http://download-west.oracle.com/docs/cd/B10464_01/web.904/b10319/toc.htm), Chapter 6, JESI Tags for Edge Side Includes.

Tag Libraries

Without tag libraries, JSPs would be less useful. Tag libraries are reusable components that developers can use on multiple JSPs. A well-designed tag library encapsulates a set of reusable functionality. Using tag libraries keeps messy scriptlets out of our JSPs.

To use tag libraries, you must define them in the JSP using the taglib directive. You must specify either an absolute Uniform Resource Identifier (URI) or a logical URI. When using a logical URI, you must specify it in the web.xml file using the taglib element. The following entry in your web.xml file will allow you to use a logical URI to access the JSTL core library:

 <taglib>     <taglib-uri>http://java.sun.com/jstl/core</taglib-uri>     <taglib-location>/WEB-INF/c.tld</taglib-location>   </taglib> 

To use the tag library in your JSPs, you will also have to place the appropriate jar file in your classpath. In this case, it would be jstl.jar. The JSP taglib directive must be added to the JSPs to complete the configuration. The following example makes the JSTL core tags available to your JSPs:

 <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> 
Note  

The c prefix used in the preceding example is the standard used by most developers, but the prefix can be any string that does not conflict with other tag libraries used on the page.

You can also add the taglib directive without adding the web.xml entry, as long as you set the URI to an absolute path . The following example allows you to access the core tag library without the web.xml entry:

 <%@ taglib uri="/WEB-INF/c.tld" prefix="c" %> 


Oracle Application Server 10g Web Development
Oracle Application Server 10g Web Development (Oracle Press)
ISBN: 0072255110
EAN: 2147483647
Year: 2004
Pages: 192

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net