HTML and CSS Reference
In-Depth Information
The actual implementation of the CDI bean can be seen in Listing 11-12. It is a simple request scoped bean with
a single property called
name
. Listing 11-13 shows the Facelets file presenting the input field to the user including a
submit button. Notice that we have a panel group that is displayed only if the CDI bean's name property is not empty.
Listing 11-12.
Simple Request Scoped CDI Bean Exposing a
name
Property
package com.apress.projsf2html5.chapter11.jsf;
import java.io.Serializable;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
@Named(value = "helloYou")
@RequestScoped
public class HelloYou implements Serializable {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Listing 11-13.
Facelets File Displaying the Input Box and Submit Button to the User
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="
http://www.w3.org/1999/xhtml
"
xmlns:h="
http://xmlns.jcp.org/jsf/html
"
xmlns:ui="
http://xmlns.jcp.org/jsf/facelets
"
>
<ui:composition template="/base.xhtml">
<ui:define name="title">
Chapter 11 - Testing - Hello You
</ui:define>
<ui:define name="top">
Chapter 11 - Testing - Hello You
</ui:define>
<ui:define name="content">
<h:form id="hello-form">
<h:outputLabel value="What's your name?" for="input-name" />
<h:inputText id="input-name" value="#{helloYou.name}" />
<h:commandButton id="submit" value="Submit" />