CDI On Tomcat Adhoc Lab ----------------------- Part 1: Getting Started with CDI -------------------------------- - Go to: http://www.seamframework.org/Weld/Downloads and download "1.1.10.Final". Unzip it to the c:\java folder. You should end up with a subdirectory c:\java\weld-1.1.10.Final - Create a Dynamic Web project named CDIWeb and configure it for JSF - Add the weld-servlet.jar file from c:\java\weld-1.1.10.Final\artifacts\weld to the project's "lib" folder - Create a managed bean class named MyBean and in it, define a property named "myprop" of type String. Initialize the property value to "Hello". - Annotate the class with @Named and @ConversationScoped. - Create a JSF XHTML file that displays the property using - Edit web.xml and add the following: org.jboss.weld.environment.servlet.Listener - Run and test Part 2: Using Conversations ---------------------------- - Create a class named "Order" in the "domain" package that implements java.io.Seriaizable, then complete it: - add fields: private int size; private boolean mushrooms; private boolean sausage; private boolean beef; - generate get/set - create read-only property: public double getPrice() { double price = 0; switch(size) { case 1: // medium price = 16.95; break; case 2: // medium price = 17.95; break; case 3: // large price = 18.95; } if (beef) price = price + 1; if (sausage) price = price + 1; if (mushrooms) price = price + 1; return price; } - Create a class named "Customer" in the "domain" package that implements java.io.Serializable, then complete it: - define String fields for "name" and "address" - generate get/set methods - Create a class named "OrderManager" in the "service" package that implements java.io.Serializable, then complete it: - annotate it with @Named and @ConversationScoped - add fields (generate get/sets, too): private Order theOrder = new Order(); private Customer theCustomer = new Customer(); private String[] ingredients; - add another field (no get/set): @Inject private Conversation conv; - write a method to process some of the order info and start a conversation public String processSize() { conv.begin(); return "/ingredients.xhtml"; } - write a method to continue the conversation and process more order info public String processIngredients() { for (String ingredient : ingredients) { if (ingredient.equals("Beef")) theOrder.setBeef(true); if (ingredient.equals("Mushrooms")) theOrder.setMushrooms(true); if (ingredient.equals("Sausage")) theOrder.setSausage(true); } return "/delivery.xhtml"; } - write method to complete the conversation public String confirmOrder() { conv.end(); System.out.println("Processing order..."); return "/confirmation.xhtml"; } - Create size.xhtml with the standard JSF XHTML boilerplate and an . Inside the form:

Enter Size


- Create ingredients.xhtml with standard JSF XHTML boilerplate and an . Inside the form:

Choose Ingredients


- Create delivery.xhtml with standard JSF XHTML boilerplate and an . Inside the form:

Enter Delivery Info

Name:
Address:

- Create confirmation.xhtml with the standard JSF XHTM boilerplate, no . In the body:

Confirmation

Thanks for the order, . The price of your pizza is:

- Test by running size.xhtml on the server.