19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

Create successful ePaper yourself

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

The h:selectManyListbox element is bound <strong>to</strong> the minor property (line<br />

52). When the page is sent <strong>to</strong> the server, the selected items are<br />

returned as an array of strings and set <strong>to</strong> the minor property.<br />

<br />

The h:selectManyCheckbox element is bound <strong>to</strong> the hobby property (line<br />

63). When the page is sent <strong>to</strong> the server, the checked boxes are returned<br />

as an array of itemValues and set <strong>to</strong> the hobby property.<br />

<br />

The h:selectTextarea element is bound <strong>to</strong> the remarks property (line 75).<br />

When the page is sent <strong>to</strong> the server, the content in the text area is<br />

returned as a string and set <strong>to</strong> the remarks property.<br />

<br />

The h:outputText element is bound <strong>to</strong> the response property (line 82).<br />

This is a read-only property in the bean. It is "" if lastName is null<br />

(lines 83-84 in Listing 44.5). When the page is returned <strong>to</strong> the client,<br />

the response property value is displayed in the output text element<br />

(line 82).<br />

<br />

The h:outputText element’s escape attribute is set <strong>to</strong> false (line 81) <strong>to</strong><br />

enable the contents <strong>to</strong> be displayed in HTML. By default, the escape<br />

attribute is true, which indicates the contents are considered as<br />

regular text.<br />

44.5 Case Study: Calcula<strong>to</strong>r<br />

This section uses JSF <strong>to</strong> develop a calcula<strong>to</strong>r <strong>to</strong> perform addition,<br />

subtraction, multiplication, and division, as shown in Figure 44.21.<br />

Figure 44.21<br />

This JSF application enables you <strong>to</strong> perform addition, subtraction,<br />

multiplication, and division.<br />

Here are the steps <strong>to</strong> develop this project:<br />

<br />

Step 1. Create a new managed bean named Calcula<strong>to</strong>r with the request<br />

scope as shown in Listing 44.7, Calcula<strong>to</strong>r.java.<br />

<br />

Step 2. Create a JSP facelet named Calcula<strong>to</strong>r as shown in Listing 44.8,<br />

Calcula<strong>to</strong>r.xhtml.<br />

Listing 44.7 Calcula<strong>to</strong>r.java<br />

<br />

20

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

Saved successfully!

Ooh no, something went wrong!