Java Reference
In-Depth Information
@Named
@RequestScoped
public class PremiumCustomerController {
private static final Logger logger = Logger.getLogger(
PremiumCustomerController.class.getName());
@Inject
@Premium
private Customer customer;
public String saveCustomer() {
PremiumCustomer premiumCustomer =
(PremiumCustomer) customer;
logger.log(Level.INFO, "Saving the following information \n"
+ "{0} {1}, discount code = {2}",
new Object[]{premiumCustomer.getFirstName(),
premiumCustomer.getLastName(),
premiumCustomer.getDiscountCode()});
//If this was a real application, we would have code to save
//customer data to the database here.
return "premium_customer_confirmation";
}
}
Since we used our @Premium qualifier to decorate the customer field, an instance
of the PremiumCustomer class is injected into that field. This is because this class
is also decorated with the @Premium qualifier.
As far as our JSF pages go, we simply access our named bean as usual using its
name, as shown in the following code;
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Create New Premium Customer</title>
</h:head>
<h:body>
<h:form>
 
Search WWH ::




Custom Search