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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>The</strong> inputText tag displays a UIInput component as a text field. <strong>The</strong> validator attribute of<br />

this inputText tag references a method, called validateName, in the bean, called customer. <strong>The</strong><br />

TLD (see “Tag Library Descriptors” on page 245) that defines the inputText tag specifies what<br />

signature the method referred to by the validator attribute must have. <strong>The</strong> same is true of the<br />

customer.submit method referenced by the action attribute of the commandButton tag. <strong>The</strong><br />

TLD specifies that the submit method must return an Object instance that specifies which page<br />

to navigate to next after the button represented by the commandButton tag is clicked.<br />

<strong>The</strong> validation method is invoked during the process validation phase of the life cycle,<br />

whereas the submit method is invoked during the invoke application phase of the life cycle.<br />

Because a method can be invoked during different phases of the life cycle, method expressions<br />

must always use the deferred evaluation syntax.<br />

Similarly to lvalue expressions, method expressions can use the . and [] operators. For example,<br />

#{object.method} is equivalent to #{object["method"]}. <strong>The</strong> literal inside the [] is coerced to<br />

String and is used to find the name of the method that matches it. Once the method is found, it<br />

is invoked or information about the method is returned.<br />

Method expressions can be used only in tag attributes and only in the following ways:<br />

■ With a single expression construct, where bean refers to a <strong>Java</strong>Beans component and method<br />

refers to a method of the <strong>Java</strong>Beans component:<br />

<br />

<strong>The</strong> expression is evaluated to a method expression, which is passed to the tag handler. <strong>The</strong><br />

method represented by the method expression can then be invoked later.<br />

■ With text only:<br />

<br />

Method expressions support literals primarily to support action attributes in <strong>Java</strong>Server<br />

Faces technology. When the method referenced by this method expression is invoked, it<br />

returns the String literal, which is then coerced to the expected return type, as defined in<br />

the tag’s TLD.<br />

Defining aTag AttributeType<br />

Unified Expression Language<br />

As explained in the previous section, all kinds of expressions can be used in tag attributes.<br />

Which kind of expression and how that expression is evaluated (whether immediately or<br />

deferred) is determined by the type attribute of the tag’s definition in the TLD (see “Tag Library<br />

Descriptors” on page 245) file that defines the tag.<br />

If you plan to create custom tags (see Chapter 8, “Custom Tags in JSP Pages”), you need to<br />

specify for each tag in the TLD what kind of expression it accepts. Table 5–2 shows the three<br />

different kinds of tag attributes that accept EL expressions, and gives examples of expressions<br />

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

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

Saved successfully!

Ooh no, something went wrong!