Home » apache-openwebbeans-1.0.0-incubating-M3-binary » org.apache.webbeans.sample » conversation » [javadoc | source]

    1   /*
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    * 
    9    *       http://www.apache.org/licenses/LICENSE-2.0
   10    * 
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   package org.apache.webbeans.sample.conversation;
   18   
   19   import java.io.Serializable;
   20   
   21   import javax.enterprise.context.Conversation;
   22   import javax.enterprise.context.RequestScoped;
   23   import javax.enterprise.inject.Default;
   24   import javax.inject.Inject;
   25   import javax.inject.Named;
   26   import javax.faces.application.FacesMessage;
   27   
   28   import org.apache.webbeans.sample.model.conversation.ConversationModel;
   29   import org.apache.webbeans.sample.util.FacesMessageUtil;
   30   
   31   @RequestScoped
   32   @Named
   33   public class ShoppingCardBean implements Serializable
   34   {
   35       private static final long serialVersionUID = 7914095399647910625L;
   36   
   37       private @Inject @Default Conversation conversation;
   38       
   39       private @Inject @Default ConversationModel model;
   40       
   41       private @Inject @Default FacesMessageUtil messageUtil;
   42       
   43       private String book;
   44       
   45       public String startConversation()
   46       {
   47           conversation.begin();
   48           
   49           messageUtil.addMessage(FacesMessage.SEVERITY_INFO, "Conversation with id : " + conversation.getId() + " is started", null);
   50           
   51           return null;
   52       }
   53       
   54       public String addNewBook()
   55       {
   56           model.getList().add(this.book);
   57           
   58           StringBuffer buffer = new StringBuffer("Your shopping card contents : [");
   59           
   60           for(String b : model.getList())
   61           {
   62               buffer.append("," + b);
   63           }
   64           
   65           messageUtil.addMessage(FacesMessage.SEVERITY_INFO, buffer.toString() + "]", null);
   66           
   67           
   68           return null;
   69       }
   70       
   71       public String endConversation()
   72       {
   73           messageUtil.addMessage(FacesMessage.SEVERITY_INFO, "Conversation with id : " + conversation.getId() + " is ended", null);
   74           
   75           conversation.end();        
   76           
   77           return null;
   78       }
   79   
   80       /**
   81        * @return the book
   82        */
   83       public String getBook()
   84       {
   85           return book;
   86       }
   87   
   88       /**
   89        * @param book the book to set
   90        */
   91       public void setBook(String book)
   92       {
   93           this.book = book;
   94       }
   95   
   96       
   97   }

Home » apache-openwebbeans-1.0.0-incubating-M3-binary » org.apache.webbeans.sample » conversation » [javadoc | source]