10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

In this example, the expression referencing the function is using immediate evaluation syntax.<br />

A page author can also use deferred evaluation syntax to reference a function in an expression,<br />

assuming that the attribute that is referencing the function can accept deferred expressions.<br />

If an attribute references a function with a deferred expression then the function is not invoked<br />

immediately; rather, it is invoked whenever the underlying technology using the function<br />

determines it should be invoked.<br />

Defining Functions<br />

To define a function, program it as a public static method in a public class. <strong>The</strong><br />

mypkg.MyLocales class in the date example defines a function that tests the equality of two<br />

Strings as follows:<br />

package mypkg;<br />

public class MyLocales {<br />

}<br />

...<br />

public static boolean equals( String l1, String l2 ) {<br />

return l1.equals(l2);<br />

}<br />

<strong>The</strong>n map the function name as used in the EL expression to the defining class and function<br />

signature in a TLD (see Chapter 8, “Custom Tags in JSP Pages”). <strong>The</strong> following functions.tld<br />

file in the date example maps the equals function to the class containing the implementation of<br />

the function equals and the signature of the function:<br />

<br />

equals<br />

mypkg.MyLocales<br />

boolean equals( java.lang.String,<br />

java.lang.String )<br />

<br />

No two functions within a tag library can have the same name.<br />

<strong>Java</strong>Beans Components<br />

<strong>Java</strong>Beans Components<br />

<strong>Java</strong>Beans components are <strong>Java</strong> classes that can be easily reused and composed together into<br />

applications. Any <strong>Java</strong> class that follows certain design conventions is a <strong>Java</strong>Beans component.<br />

<strong>Java</strong>Server Pages technology directly supports using <strong>Java</strong>Beans components with standard JSP<br />

language elements. You can easily create and initialize beans and get and set the values of their<br />

properties.<br />

Chapter 5 • <strong>Java</strong>Server PagesTechnology 165

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!