Learn Java for Web Development

(Tina Meador) #1

274 CHAPTER 6: Component-Based Web Development Using JSF 2


Listing 6-1 illustrates the code of the form.xhtml file.


Listing 6-1. form.xhtml



  1. <?xml version="1.0" encoding="UTF-8"?>

  2. <!DOCTYPE html >

  3. <html xmlns="http://www.w3.org/1999/xhtml"

  4. xmlns:h="http://java.sun.com/jsf/html">







  5. First JSF app








  6. Enter your name:
























   Line 4: The xmlns attribute declares the JSF namespace.
 Lines 6, 9, 12, 13, and 14: Some tags have prefixes, such as h:head and
h:inputText. These are JSF tags. The h:inputText and h:commandButton tags
correspond to the text field and Submit button in Figure 6-11.
 Line 13: The input fields are linked to object properties. For example,
attributevalue="#{helloBean.name}" tells the JSF implementation to link the
text field with the name property of a user object.
 Line 14: The #{...} delimiters enclose expressions in the JSF expression
language.
 Line 14: When you enter the name and click the Submit button, the hello.xhtml
file is displayed, as specified in the action attribute of the h:commandButton tag.

Listing 6-2 illustrates the code of the hello.xhtml file.


Listing 6-2. hello.xhtml



  1. <?xml version="1.0" encoding="UTF-8"?>

  2. <!DOCTYPE html>

  3. <html xmlns="http://www.w3.org/1999/xhtml"

  4. xmlns:h="http://java.sun.com/jsf/html">







  5. Hello world








  6. Hello #{helloBean.name}









Free download pdf