Skip Headers

Oracle9iAS Containers for J2EE JSP Tag Libraries and Utilities Reference
Release 2 (9.0.2)

Part Number A95883-01
Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Go to previous page Go to next page

2
JavaBeans for Extended Types

This chapter describes portable JavaBeans provided with OC4J for use as extended types. For JSP pages, these types offer advantages over Java primitive types or standard java.lang types.

The chapter consists of the following:

Overview of JML Extended Types

JSP pages generally rely on core Java types in representing scalar values. However, neither of the following type categories is fully suitable for use in JSP pages:

To work around these limitations, OC4J provides the following JavaBean classes in the oracle.jsp.jml package to act as wrappers for the most common Java types:

Each of these classes has a single attribute, value, and includes methods to get the value, set the value from input in various formats, test whether the value is equal to a value specified in any of several formats, and convert the value to a string.

Alternatively, instead of using the getValue() and setValue() methods, you can use the jsp:getProperty and jsp:setProperty tags, as with any other bean.

The following example creates a JmlNumber instance called count that has application scope:

<jsp:useBean id="count" class="oracle.jsp.jml.JmlNumber" scope="application" />

Later, assuming that the value has been set elsewhere, you can access it as follows:

<h3> The current count is <%=count.getValue() %> </h3>

The following example creates a JmlNumber instance called maxSize that has request scope, and sets it using setProperty:

<jsp:useBean id="maxSize" class="oracle.jsp.jml.JmlNumber" scope="request" >
    <jsp:setProperty name="maxSize" property="value" value="<%= 25 %>" />
</jsp:useBean> 

JML Extended Type Descriptions

This section documents the public methods of the four extended types--JmlBoolean, JmlNumber, JmlFPNumber, and JmlString--followed by an example.


Note:

To use the JML extended types, verify that the ojsputil.jar file is installed and in your classpath. This file is supplied with OC4J.


Type JmlBoolean

A JmlBoolean object represents a Java boolean value.

The getValue() and setValue() methods get or set the value property of the bean as a Java boolean value.

The setTypedValue() method has several signatures and can set the value property from a string (such as "true" or "false"), a java.lang.Boolean value, a Java boolean value, or a JmlBoolean value. For the string input, conversion of the string is performed according to the same rules as for the valueOf() method of the java.lang.Boolean class.

The equals() method tests whether the value property is equal to the specified Java boolean value.

The typedEquals() method has several signatures and tests whether the value property has a value equivalent to a specified string (such as "true" or "false"), java.lang.Boolean value, or JmlBoolean value.

The toString() method returns the value property as a java.lang.String value, either "true" or "false".

Type JmlNumber

A JmlNumber object represents a 32-bit number equivalent to a Java int value.

The getValue() and setValue() methods get or set the value property of the bean as a Java int value.

The setTypedValue() method has several signatures and can set the value property from a string, a java.lang.Integer value, a Java int value, or a JmlNumber value. For the string input, conversion of the string is performed according to the same rules as for the decode() method of the java.lang.Integer class.

The equals() method tests whether the value property is equal to the specified Java int value.

The typedEquals() method has several signatures and tests whether the value property has a value equivalent to a specified string (such as "1234"), java.lang.Integer value, or JmlNumber value.

The toString() method returns the value property as an equivalent java.lang.String value (such as "1234"). This method has the same functionality as the toString() method of the java.lang.Integer class.

Type JmlFPNumber

A JmlFPNumber object represents a 64-bit floating point number equivalent to a Java double value.

The getValue() and setValue() methods get or set the value property of the bean as a Java double value.

The setTypedValue() method has several signatures and can set the value property from a string (such as "3.57"), a java.lang.Integer value, a Java int value, a java.lang.Float value, a Java float value, a java.lang.Double value, a Java double value, or a JmlFPNumber value. For the string input, conversion of the string is according to the same rules as for the valueOf() method of the java.lang.Double class.

The equals() method tests whether the value property is equal to the specified Java double value.

The typedEquals() method has several signatures and tests whether the value property has a value equivalent to a specified string (such as "3.57"), java.lang.Integer value, Java int value, java.lang.Float value, Java float value, java.lang.Double value, Java double value, or JmlFPNumber value.

The toString() method returns the value property as a java.lang.String value (such as "3.57"). This method has the same functionality as the toString() method of the java.lang.Double class.

Type JmlString

A JmlString object represents a java.lang.String value.

The getValue() and setValue() methods get or set the value property of the bean as a java.lang.String value. If the input in a setValue() call is null, then the value property is set to an empty (zero-length) string.

The toString() method is functionally equivalent to the getValue() method.

The setTypedValue() method sets the value property according to the specified JmlString value. If the JmlString value is null, then the value property is set to an empty (zero-length) string.

The isEmpty() method tests whether the value property is an empty (zero-length) string: ""

The equals() method has two signatures and tests whether the value property is equal to a specified java.lang.String value or JmlString value.

JML Extended Types Example

This example illustrates the use of JML extended type JavaBeans for management of simple types at scope. The page declares four session objects--one for each JML type. The page presents a form that allows you to enter values for each of these types. Once new values are submitted, the form displays both the new values and the previously set values. In the process of generating this output, the page updates the session objects with the new form values.

<jsp:useBean id = "submitCount" class = "oracle.jsp.jml.JmlNumber" scope = "session" />

<jsp:useBean id = "bool" class = "oracle.jsp.jml.JmlBoolean" scope = "session" >
        <jsp:setProperty name = "bool" property = "value" param = "fBoolean" />
</jsp:useBean>

<jsp:useBean id = "num" class = "oracle.jsp.jml.JmlNumber" scope = "session" >
        <jsp:setProperty name = "num" property = "value" param = "fNumber" />
</jsp:useBean>

<jsp:useBean id = "fpnum" class = "oracle.jsp.jml.JmlFPNumber" scope = "session" >
        <jsp:setProperty name = "fpnum" property = "value" param = "fFPNumber" />
</jsp:useBean>

<jsp:useBean id = "str" class = "oracle.jsp.jml.JmlString" scope = "session" >
        <jsp:setProperty name = "str" property = "value" param = "fString" />
</jsp:useBean>


<HTML>

<HEAD>
        <META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">
        <META NAME="GENERATOR" Content="Visual Page 1.1 for Windows">
        <TITLE>Extended Datatypes Sample</TITLE>
</HEAD>

<BODY BACKGROUND="images/bg.gif" BGCOLOR="#FFFFFF">

<% if (submitCount.getValue() > 1) { %>
        <h3> Last submitted values </h3>
        <ul>
                <li> bool: <%= bool.getValue() %>
                <li> num: <%= num.getValue() %>
                <li> fpnum: <%= fpnum.getValue() %>
                <li> string: <%= str.getValue() %>
        </ul>
<% }

   if (submitCount.getValue() > 0) { %>

        <jsp:setProperty name = "bool" property = "value" param = "fBoolean" />
        <jsp:setProperty name = "num" property = "value" param = "fNumber" />
        <jsp:setProperty name = "fpnum" property = "value" param = "fFPNumber" />
        <jsp:setProperty name = "str" property = "value" param = "fString" />

        <h3> New submitted values </h3>
        <ul>
                <li> bool: <jsp:getProperty name="bool" property="value" />
                <li> num: <jsp:getProperty name="num" property="value" />
                <li> fpnum: <jsp:getProperty name="fpnum" property="value" />
                <li> string: <jsp:getProperty name="str" property="value" />
        </ul>
<% } %>

<jsp:setProperty name = "submitCount" property = "value" value = "<%= submitCount.getValue() + 1 
%>" />

<FORM ACTION="index.jsp" METHOD="POST" ENCTYPE="application/x-www-form-urlencoded">
<P> <pre>
 boolean test: <INPUT TYPE="text" NAME="fBoolean" VALUE="<%= bool.getValue() %>" >
  number test: <INPUT TYPE="text" NAME="fNumber" VALUE="<%= num.getValue() %>" >
fpnumber test: <INPUT TYPE="text" NAME="fFPNumber" VALUE="<%= fpnum.getValue() %>" >
  string test: <INPUT TYPE="text" NAME="fString" VALUE= "<%= str.getValue() %>" >
</pre>

<P> <INPUT TYPE="submit">

</FORM>

</BODY>

</HTML>


Go to previous page Go to next page
Oracle
Copyright © 2002 Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index