Java Reference
In-Depth Information
public class CustomerController {
private Customer customer;
public Customer getCustomer() {
return customer;
public void setCustomer(Customer customer) {
this.customer = customer;
public String navigateToConfirmation() {
//In a real application we would
//Save customer data to the database here.
return "confirmation";
In the preceding class, an instance of the Customer class is injected at runtime; this
is accomplished via the @Inject annotation. This annotation allows us to easily use
dependency injection in CDI applications. Since the Customer class is annotated with
the @RequestScoped annotation, a new instance of Customer will be injected for
every request.
The navigateToConfirmation() method in the preceding class is invoked when
the user clicks on the Submit button on the page. The navigateToConfirmation()
method works just like an equivalent method in a JSF managed bean would, that is,
it returns a string and the application navigates to an appropriate page based on the
value of that string. Like with JSF, by default, the target page's name with an .xhtml
extension is the return value of this method. For example, if no exceptions are
thrown in the navigateToConfirmation() method, the user is directed to a page
named confirmation.xhtml :
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns=""
Search WWH ::

Custom Search