]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Continiued:
authorRoland Haeder <roland@mxchange.org>
Wed, 16 Sep 2015 10:05:08 +0000 (12:05 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 16 Sep 2015 11:26:34 +0000 (13:26 +0200)
- moved creating of Customer instance to proper bean
- renamed that bean to reflect its purpose better
- added a lot logger messages
- updated jars
Signed-off-by:Roland Häder <roland@mxchange.org>

lib/jcoreee.jar
lib/jshop-core.jar
lib/jshop-ee-lib.jar
src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebBean.java
src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebBean.java
src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebController.java
src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebBean.java
src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebController.java
web/WEB-INF/templates/generic/gender_selection_box.tpl
web/WEB-INF/templates/guest/guest_personal_data.tpl
web/WEB-INF/templates/guest/guest_registration_form.tpl

index 20252ca040b5e56afe2e392067112c8f883da4a8..32a615bb007b46294addca4ea2c1ef2ab8f6eaba 100644 (file)
Binary files a/lib/jcoreee.jar and b/lib/jcoreee.jar differ
index eda325ad96c4276316490de4a45cd21f95ecefb3..4a925a98e00a79fc5b0c6700114d4cd5499d74b2 100644 (file)
Binary files a/lib/jshop-core.jar and b/lib/jshop-core.jar differ
index d3501cbe030e16157805399001c1e3c1908f669b..1a0b0d99011926ed373a8b88e79e160666f7792d 100644 (file)
Binary files a/lib/jshop-ee-lib.jar and b/lib/jshop-ee-lib.jar differ
index d9c540d4273ba6617dfe9c6bb96b55e8ee2d00eb..95c2e71cb465b964c0cfb61bd8133746cd22aa96 100644 (file)
@@ -71,27 +71,42 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
 
        /**
         * Default constructor
-        *
-        * @throws javax.naming.NamingException If something happened?
         */
-       public BasketWebBean () throws NamingException {
-               // Get initial context
-               Context context = new InitialContext();
-
+       public BasketWebBean () {
                // Get new application instance
                this.basket = new ShopBasket();
 
-               // Try to lookup
-               this.basketBean = (BasketSessionBeanRemote) context.lookup("ejb/stateless-basket"); //NOI18N
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Try to lookup
+                       this.basketBean = (BasketSessionBeanRemote) context.lookup("ejb/stateless-basket"); //NOI18N
+               } catch (final NamingException ex) {
+                       // Continue to throw
+                       throw new FacesException(ex);
+               }
        }
 
        @Override
        public String addItem (final Product product) {
+               // Trace message
+               this.getLogger().logTrace(MessageFormat.format("addItem: product={0} - CALLED!", product));
+
+               // product should not be null
+               if (null == product) {
+                       // Abort here
+                       throw new NullPointerException("product is null");
+               }
+
                // Generate item instance
                AddableBasketItem item = new BasketItem(product, this.getAmount());
 
                // Is amount set?
                if (this.getAmount() == null) {
+                       // Trace message
+                       this.getLogger().logTrace("addItem: amount not specified, returning null ... - EXIT!");
+
                        // No amount specified?!
                        return null;
                }
@@ -109,6 +124,9 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
                        // Remove amount
                        this.setAmount(null);
 
+                       // Trace message
+                       this.getLogger().logTrace(MessageFormat.format("addItem: item {0} - has been added to basket. - EXIT!", item));
+
                        // Added
                        return "item_added"; //NOI18N
                } catch (final BasketItemAlreadyAddedException ex) {
@@ -119,12 +137,24 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
 
        @Override
        public List<AddableBasketItem> allItems () {
+               // Trace message
+               this.getLogger().logTrace("allItems: CALLED!");
+
                // Deligate to basket instance
-               return this.basket.getAll();
+               List<AddableBasketItem> list = this.basket.getAll();
+
+               // Trace message
+               this.getLogger().logTrace(MessageFormat.format("allItems: list={0} - EXIT!", list));
+
+               // Return it
+               return list;
        }
 
        @Override
        public Float calculateCurrentItemPrice () {
+               // Trace message
+               this.getLogger().logTrace("calculateCurrentItemPrice: CALLED!");
+
                // Is the current item/amount set?
                if (this.getCurrentItem() == null) {
                        // Current item is null
@@ -140,12 +170,24 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
                // Caculate item's price
                Float totalPrice = (this.getCurrentItem().getProduct().getPrice() * this.getCurrentItem().getAmount());
 
+               // Trace message
+               this.getLogger().logTrace(MessageFormat.format("calculateCurrentItemPrice: totalPrice={0} - EXIT!", totalPrice));
+
                // Return it
                return totalPrice;
        }
 
        @Override
        public Float calculateItemPrice (final AddableBasketItem item) {
+               // Trace message
+               this.getLogger().logTrace(MessageFormat.format("calculateItemPrice: item={0} - CALLED!", item));
+
+               // item must not be null
+               if (null == item) {
+                       // Abort here
+                       throw new NullPointerException("item is null");
+               }
+
                // Default value
                Float totalPrice = 0.0f;
 
@@ -155,12 +197,18 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
                        totalPrice = (item.getProduct().getPrice() * item.getAmount());
                }
 
+               // Trace message
+               this.getLogger().logTrace(MessageFormat.format("calculateItemPrice: totalPrice={0} - EXIT!", totalPrice));
+
                // Return it
                return totalPrice;
        }
 
        @Override
        public Float calculateTotalPrice () {
+               // Trace message
+               this.getLogger().logTrace("calculateTotalPrice: CALLED!");
+
                // Init total price
                Float totalPrice = 0.0f;
 
@@ -173,12 +221,24 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
                        }
                }
 
+               // Trace message
+               this.getLogger().logTrace(MessageFormat.format("calculateTotalPrice: totalPrice={0} - EXIT!", totalPrice));
+
                // Return final sum
                return totalPrice;
        }
 
        @Override
        public String changeItem (final AddableBasketItem item) {
+               // Trace message
+               this.getLogger().logTrace(MessageFormat.format("changeItem: item={0} - CALLED!", item));
+
+               // item shall not be null
+               if (null == item) {
+                       // Abort here
+                       throw new NullPointerException("item is null");
+               }
+
                // Default is not found
                String targetPage = "item_not_changed"; //NOI18N
 
@@ -192,6 +252,9 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
                        }
                }
 
+               // Trace message
+               this.getLogger().logTrace(MessageFormat.format("changeItem: targetPage={0} - EXIT!", targetPage));
+
                // Return page
                return targetPage;
        }
@@ -225,19 +288,37 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
 
        @Override
        public Long getItemAmount (final Product product) {
+               // Trace message
+               this.getLogger().logTrace(MessageFormat.format("getItemAmount: product={0} - CALLED!", product));
+
+               // product should not be null
+               if (null == product) {
+                       // Abort here
+                       throw new NullPointerException("product is null");
+               }
+
                // Initial value is zero
                Long itemAmount = 0L;
 
                // Iterate over all
                for (final AddableBasketItem item : this.allItems()) {
+                       // Debug message
+                       this.getLogger().logDebug(MessageFormat.format("getItemAmount: item={0}", item));
+
                        // Is this product instance and same?
-                       if ((item.isProductType()) && (item.getProduct().equals(product))) {
+                       if (null == item) {
+                               // item is null
+                               throw new NullPointerException("item is null");
+                       } else if ((item.isProductType()) && (item.getProduct().equals(product))) {
                                // Found it
                                itemAmount = item.getAmount();
                                break;
                        }
                }
 
+               // Trace message
+               this.getLogger().logTrace(MessageFormat.format("getItemAmount: itemAmount={0} - EXIT!", itemAmount));
+
                // Return it
                return itemAmount;
        }
@@ -274,6 +355,9 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
 
        @Override
        public boolean isProductAdded (final Product product) {
+               // Trace message
+               this.getLogger().logTrace(MessageFormat.format("isProductAdded: product={0} - EXIT!", product));
+
                // Must not be null
                if (null == product) {
                        // Abort here
@@ -283,24 +367,39 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
                // Generate fake instance
                AddableBasketItem fake = new BasketItem(product);
 
+               // Debug message
+               this.getLogger().logDebug(MessageFormat.format("isProductAdded: fake={0}", fake));
+
                // Ask bean about it
                boolean isAdded = this.basket.isAdded(fake);
 
+               // Debug message
+               this.getLogger().logDebug(MessageFormat.format("isProductAdded: isAdded={0}", isAdded));
+
                // Is it added?
                if (isAdded) {
                        // Get item
                        AddableBasketItem item = this.getItemFromProduct(product);
 
+                       // Debug message
+                       this.getLogger().logDebug(MessageFormat.format("isProductAdded: item={0} - setting as current item.", item));
+
                        // Set this as current item
                        this.setCurrentItem(item);
                }
 
+               // Trace message
+               this.getLogger().logTrace(MessageFormat.format("isProductAdded: isAdded={0} - EXIT!", isAdded));
+
                // Return status
                return isAdded;
        }
 
        @Override
        public String outputLastAddedItem () {
+               // Trace message
+               this.getLogger().logTrace("outputLastAddedItem: CALLED!");
+
                // Default message
                String lastItem = ""; //NOI18N
 
@@ -312,7 +411,7 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
                        // Get type
                        switch (item.getItemType()) {
                                case "product": // Sellable product //NOI18N
-                                       assert(item.getProduct() instanceof Product) : MessageFormat.format("item {0} has no product instance set.", item); //NOI18N
+                                       assert (item.getProduct() instanceof Product) : MessageFormat.format("item {0} has no product instance set.", item); //NOI18N
 
                                        // Get title
                                        lastItem = item.getProduct().getTitle();
@@ -323,6 +422,9 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
                        }
                }
 
+               // Trace message
+               this.getLogger().logTrace(MessageFormat.format("outputLastAddedItem: lastItem={0} - EXIT!", lastItem));
+
                // Return it
                return lastItem;
        }
@@ -345,6 +447,9 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
         * @return Item instance or null if not found
         */
        private AddableBasketItem getItemFromProduct (final Product product) {
+               // Trace message
+               this.getLogger().logTrace(MessageFormat.format("getItemFromProduct: product={0} - CALLED!", product));
+
                // Product must not be null
                if (null == product) {
                        // Abort here
@@ -357,11 +462,20 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
                // Create fake instance
                AddableBasketItem fake = new BasketItem(product);
 
+               // Debug message
+               this.getLogger().logDebug(MessageFormat.format("getItemFromProduct: fake={0}", fake));
+
                // Get all items
                List<AddableBasketItem> list = this.basket.getAll();
 
+               // Debug message
+               this.getLogger().logDebug(MessageFormat.format("getItemFromProduct: list={0}", list));
+
                // Check all entries
                for (final AddableBasketItem item : list) {
+                       // Debug message
+                       this.getLogger().logDebug(MessageFormat.format("getItemFromProduct: item={0}", item));
+
                        // item must not be null
                        if (null == item) {
                                // Abort here
@@ -376,6 +490,9 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
                        }
                }
 
+               // Trace message
+               this.getLogger().logTrace(MessageFormat.format("getItemFromProduct: foundItem={0} - EXIT!", foundItem));
+
                // Return it
                return foundItem;
        }
index d36c25953d24ebf6667f5717b4f381b3d8931d24..3de6f0eab6987cb717694b7e1bf2648adadcafff 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.mxchange.pizzaapplication.beans.checkout;
 
+import java.text.MessageFormat;
 import java.util.List;
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
@@ -33,14 +34,13 @@ import javax.jms.Session;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
-import org.mxchange.jcore.model.contact.gender.Gender;
 import org.mxchange.jcoreee.beans.BaseFrameworkBean;
 import org.mxchange.jshopcore.model.basket.AddableBasketItem;
 import org.mxchange.jshopcore.model.customer.Customer;
-import org.mxchange.jshopcore.model.customer.ShopCustomer;
 import org.mxchange.jshopcore.wrapper.CheckoutWrapper;
 import org.mxchange.jshopcore.wrapper.WrapableCheckout;
 import org.mxchange.pizzaapplication.beans.basket.BasketWebController;
+import org.mxchange.pizzaapplication.beans.customer.CustomerWebController;
 
 /**
  * Checkout controller
@@ -88,85 +88,53 @@ public class CheckoutWebBean extends BaseFrameworkBean implements CheckoutWebCon
        @Inject
        private BasketWebController basketController;
 
-       /////////////////////// Properties /////////////////////
        /**
-        * Gender
+        * Customer bean
         */
-       private Gender gender;
-
-       /**
-        * First name
-        */
-       private String firstName;
-
-       /**
-        * Family name
-        */
-       private String familyName;
-
-       /**
-        * Company name
-        */
-       private String companyName;
-
-       /**
-        * Street
-        */
-       private String street;
-
-       /**
-        * House number
-        */
-       private Long houseNumber;
-
-       /**
-        * ZIP code
-        */
-       private Long zipCode;
-
-       /**
-        * City
-        */
-       private String city;
-
-       /**
-        * Phone number
-        */
-       private String phoneNumber;
-
-       /**
-        * Fax number
-        */
-       private String faxNumber;
-
-       /**
-        * Cellphone number
-        */
-       private String cellphoneNumber;
+       @Inject
+       private CustomerWebController customerController;
 
        @Override
        public String doCheckout () {
-               // Is the bean set?
+               // Trace message
+               this.getLogger().logTrace("doCheckout: CALLED!");
+
+               // Are the beans set?
                if (null == this.basketController) {
                        // Abort here
                        throw new NullPointerException("basketController is null"); //NOI18N
+               } else if (null == this.customerController) {
+                       // Abort here
+                       throw new NullPointerException("customer is null"); //NOI18N
                }
 
                // Are at least the required fields set?
-               if (!this.isRequiredPersonalDataSet()) {
+               if (!this.customerController.isRequiredPersonalDataSet()) {
+                       // Trace message
+                       this.getLogger().logTrace("doCheckout: Not all required fields are set, returning checkout2 ... - EXIT!");
+
                        // Not set, should not happen
                        return "checkout2"; //NOI18N
                } else if (this.basketController.isEmpty()) {
+                       // Trace message
+                       this.getLogger().logTrace("doCheckout: basket is empty, returning empty_basket ... - EXIT!");
+
                        // Nothing to order
                        return "empty_basket"; //NOI18N
                }
 
                // Create customer instance
-               Customer customer = this.createCustomer();
+               Customer customer = this.customerController.createInstance();
+
+               // Debug message
+               this.getLogger().logDebug(MessageFormat.format("doCheckout: customer={0}", customer));
 
                // Get ordered list
                List<AddableBasketItem> list = this.basketController.allItems();
 
+               // Debug message
+               this.getLogger().logTrace(MessageFormat.format("doCheckout: list={0}", list));
+
                // Construct container
                WrapableCheckout wrapper = new CheckoutWrapper();
                wrapper.setCustomer(customer);
@@ -191,116 +159,6 @@ public class CheckoutWebBean extends BaseFrameworkBean implements CheckoutWebCon
                return "checkout_done"; //NOI18N
        }
 
-       @Override
-       public String getCellphoneNumber () {
-               return this.cellphoneNumber;
-       }
-
-       @Override
-       public void setCellphoneNumber (final String cellphoneNumber) {
-               this.cellphoneNumber = cellphoneNumber;
-       }
-
-       @Override
-       public String getCity () {
-               return this.city;
-       }
-
-       @Override
-       public void setCity (final String city) {
-               this.city = city;
-       }
-
-       @Override
-       public String getCompanyName () {
-               return this.companyName;
-       }
-
-       @Override
-       public void setCompanyName (final String companyName) {
-               this.companyName = companyName;
-       }
-
-       @Override
-       public String getFamilyName () {
-               return this.familyName;
-       }
-
-       @Override
-       public void setFamilyName (final String familyName) {
-               this.familyName = familyName;
-       }
-
-       @Override
-       public String getFaxNumber () {
-               return this.faxNumber;
-       }
-
-       @Override
-       public void setFaxNumber (final String faxNumber) {
-               this.faxNumber = faxNumber;
-       }
-
-       @Override
-       public String getFirstName () {
-               return this.firstName;
-       }
-
-       @Override
-       public void setFirstName (final String firstName) {
-               this.firstName = firstName;
-       }
-
-       @Override
-       public Gender getGender () {
-               return this.gender;
-       }
-
-       @Override
-       public void setGender (final Gender gender) {
-               this.gender = gender;
-       }
-
-       @Override
-       public Long getHouseNumber () {
-               return this.houseNumber;
-       }
-
-       @Override
-       public void setHouseNumber (final Long houseNumber) {
-               this.houseNumber = houseNumber;
-       }
-
-       @Override
-       public String getPhoneNumber () {
-               return this.phoneNumber;
-       }
-
-       @Override
-       public void setPhoneNumber (final String phoneNumber) {
-               this.phoneNumber = phoneNumber;
-       }
-
-       @Override
-       public String getStreet () {
-               return this.street;
-       }
-
-       @Override
-       public void setStreet (final String street) {
-               this.street = street;
-       }
-
-       @Override
-       public Long getZipCode () {
-               return this.zipCode;
-       }
-
-       @Override
-       public void setZipCode (final Long zipCode) {
-               this.zipCode = zipCode;
-       }
-
        @PostConstruct
        public void init () {
                // Call super init for getting resource bundle
@@ -324,6 +182,9 @@ public class CheckoutWebBean extends BaseFrameworkBean implements CheckoutWebCon
 
                        // And message producer
                        this.messageProducer = session.createProducer(queue);
+
+                       // Finally the message instance itself
+                       this.message = this.session.createObjectMessage();
                } catch (final NamingException | JMSException e) {
                        // Continued to throw
                        throw new FacesException(e);
@@ -345,40 +206,4 @@ public class CheckoutWebBean extends BaseFrameworkBean implements CheckoutWebCon
                        throw new FacesException(ex);
                }
        }
-
-       /**
-        * Creates a full customer instance
-        *
-        * @return Customer instance
-        */
-       private Customer createCustomer () {
-               // Required personal data must be set
-               assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
-
-               // Create new customer instance
-               Customer customer = new ShopCustomer();
-               customer.setGender(this.getGender());
-               customer.setFirstName(this.getFirstName());
-               customer.setFamilyName(this.getFamilyName());
-               customer.setCompanyName(this.getCompanyName());
-               customer.setStreet(this.getStreet());
-               customer.setHouseNumber(this.getHouseNumber());
-               customer.setZipCode(this.getZipCode());
-               customer.setCity(this.getCity());
-               customer.setPhoneNumber(this.getPhoneNumber());
-               customer.setFaxNumber(this.getFaxNumber());
-               customer.setCellphoneNumber(this.getCellphoneNumber());
-
-               // Return it
-               return customer;
-       }
-
-       /**
-        * Checks if the required personal data is set
-        *
-        * @return Whether the required personal data is set
-        */
-       private boolean isRequiredPersonalDataSet () {
-               return ((this.getGender() != null) && (this.getFirstName() != null) && (this.getFamilyName() != null) && (this.getStreet() != null) && (this.getHouseNumber() != null) && (this.getZipCode() != null) && (this.getCity() != null));
-       }
 }
index cd2f6efa0a074fb4e4a2f1c913e210369f7aaa7b..4e30f29f417dc44996452519b2c17d0d8e320ee4 100644 (file)
@@ -17,7 +17,6 @@
 package org.mxchange.pizzaapplication.beans.checkout;
 
 import java.io.Serializable;
-import org.mxchange.jcore.model.contact.gender.Gender;
 
 /**
  * An interface for the shop
@@ -31,158 +30,4 @@ public interface CheckoutWebController extends Serializable {
         * @return Page redirection target
         */
        public String doCheckout ();
-
-       /**
-        * Getter for cellphone number
-        *
-        * @return Cellphone number
-        */
-       public String getCellphoneNumber ();
-
-       /**
-        * Setter for cellphone number
-        *
-        * @param cellphoneNumber Cellphone number
-        */
-       public void setCellphoneNumber (final String cellphoneNumber);
-
-       /**
-        * Getter for city
-        *
-        * @return Cellphone number
-        */
-       public String getCity ();
-
-       /**
-        * Setter for city
-        *
-        * @param city City
-        */
-       public void setCity (final String city);
-
-       /**
-        * Getter for company name
-        *
-        * @return City
-        */
-       public String getCompanyName ();
-
-       /**
-        * Setter for company name
-        *
-        * @param companyName Company name
-        */
-       public void setCompanyName (final String companyName);
-
-       /**
-        * Getter for family name
-        *
-        * @return Company name
-        */
-       public String getFamilyName ();
-
-       /**
-        * Setter for family name
-        *
-        * @param familyName Family name
-        */
-       public void setFamilyName (final String familyName);
-
-       /**
-        * Getter for fax number
-        *
-        * @return Family name
-        */
-       public String getFaxNumber ();
-
-       /**
-        * Setter for fax number
-        *
-        * @param faxNumber First name
-        */
-       public void setFaxNumber (final String faxNumber);
-
-       /**
-        * Getter for first name
-        *
-        * @return First name
-        */
-       public String getFirstName ();
-
-       /**
-        * Setter for first name
-        *
-        * @param firstName Gender
-        */
-       public void setFirstName (final String firstName);
-
-       /**
-        * Getter for gender
-        *
-        * @return Gender
-        */
-       public Gender getGender ();
-
-       /**
-        * Setter for gender
-        *
-        * @param gender Gender
-        */
-       public void setGender (final Gender gender);
-
-       /**
-        * Getter for house number
-        *
-        * @return House number
-        */
-       public Long getHouseNumber ();
-
-       /**
-        * Setter for house number
-        *
-        * @param houseNumber House number
-        */
-       public void setHouseNumber (final Long houseNumber);
-
-       /**
-        * Getter for phone number
-        *
-        * @return Phone number
-        */
-       public String getPhoneNumber ();
-
-       /**
-        * Setter for phone number
-        *
-        * @param phoneNumber Phone number
-        */
-       public void setPhoneNumber (final String phoneNumber);
-
-       /**
-        * Getter for street
-        *
-        * @return Street
-        */
-       public String getStreet ();
-
-       /**
-        * Setter for street
-        *
-        * @param street Street
-        */
-       public void setStreet (final String street);
-
-       /**
-        * Getter for ZIP code
-        *
-        * @return ZIP code
-        */
-       public Long getZipCode ();
-
-       /**
-        * Setter for ZIP code
-        *
-        * @param zipCode ZIP code
-        */
-       public void setZipCode (final Long zipCode);
 }
index 6adf22c0e264ddc9bdac2886f9e5bc3d63839362..bc76943a92bfbbb9e8a9634b19d80857831a3b06 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.mxchange.pizzaapplication.beans.customer;
 
+import java.text.MessageFormat;
 import javax.annotation.PostConstruct;
 import javax.enterprise.context.SessionScoped;
 import javax.inject.Named;
@@ -24,14 +25,16 @@ import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import org.mxchange.jcore.model.contact.gender.Gender;
 import org.mxchange.jcoreee.beans.BaseFrameworkBean;
+import org.mxchange.jshopcore.model.customer.Customer;
 import org.mxchange.jshopcore.model.customer.CustomerSessionBeanRemote;
+import org.mxchange.jshopcore.model.customer.ShopCustomer;
 
 /**
  * A customer bean which hides the customer instance
  *
  * @author Roland Haeder<roland@mxchange.org>
  */
-@Named("customer")
+@Named("customerController")
 @SessionScoped
 public class CustomerWebBean extends BaseFrameworkBean implements CustomerWebController {
        /**
@@ -131,6 +134,34 @@ public class CustomerWebBean extends BaseFrameworkBean implements CustomerWebCon
                this.customerBean = (CustomerSessionBeanRemote) context.lookup("ejb/stateless-customer");
        }
 
+       @Override
+       public Customer createInstance () {
+               // Trace message
+               this.getLogger().logTrace("createInstance: CALLED!");
+               // Required personal data must be set
+               assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
+
+               // Create new customer instance
+               Customer customer = new ShopCustomer();
+               customer.setGender(this.getGender());
+               customer.setFirstName(this.getFirstName());
+               customer.setFamilyName(this.getFamilyName());
+               customer.setCompanyName(this.getCompanyName());
+               customer.setStreet(this.getStreet());
+               customer.setHouseNumber(this.getHouseNumber());
+               customer.setZipCode(this.getZipCode());
+               customer.setCity(this.getCity());
+               customer.setPhoneNumber(this.getPhoneNumber());
+               customer.setFaxNumber(this.getFaxNumber());
+               customer.setCellphoneNumber(this.getCellphoneNumber());
+
+               // Trace message
+               this.getLogger().logTrace(MessageFormat.format("createInstance: customer={0} - EXIT!", customer));
+
+               // Return it
+               return customer;
+       }
+
        @PostConstruct
        public void init () throws RuntimeException {
                // Call super init first
@@ -266,4 +297,9 @@ public class CustomerWebBean extends BaseFrameworkBean implements CustomerWebCon
        public void setCellphoneNumber (final String cellphoneNumber) {
                this.cellphoneNumber = cellphoneNumber;
        }
+
+       @Override
+       public boolean isRequiredPersonalDataSet () {
+               return ((this.getGender() != null) && (this.getFirstName() != null) && (this.getFamilyName() != null) && (this.getStreet() != null) && (this.getHouseNumber() != null) && (this.getZipCode() != null) && (this.getCity() != null));
+       }
 }
index 691211b5a95d3d30ed9badfec68c4eb145a2c6c0..e912d05dfe83b872436f5e0973d013c84091f1c6 100644 (file)
@@ -18,6 +18,7 @@ package org.mxchange.pizzaapplication.beans.customer;
 
 import java.io.Serializable;
 import org.mxchange.jcore.model.contact.gender.Gender;
+import org.mxchange.jshopcore.model.customer.Customer;
 
 /**
  * An interface for customer beans
@@ -26,6 +27,13 @@ import org.mxchange.jcore.model.contact.gender.Gender;
  */
 public interface CustomerWebController extends Serializable {
 
+       /**
+        * Creates an instance from all properties
+        *
+        * @return A Customer instance
+        */
+       public Customer createInstance ();
+
        /**
         * Gender of the contact
         *
@@ -207,4 +215,11 @@ public interface CustomerWebController extends Serializable {
         * @param cellphoneNumber the cellphoneNumber to set
         */
        public void setCellphoneNumber (final String cellphoneNumber);
+
+       /**
+        * Checks whether all required personal data is set
+        *
+        * @return Whether the required personal data is set
+        */
+       public boolean isRequiredPersonalDataSet ();
 }
index 2a5dd7dcd03b6bad01f411215182819ac44199bb..422ace8d49e56c9dbe349f356757c1b5a66c7725 100644 (file)
@@ -5,7 +5,7 @@
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets">
 
-       <h:selectOneMenu class="select" id="gender" value="#{customer.gender}">
+       <h:selectOneMenu class="select" id="gender" value="#{customerController.gender}">
                <f:selectItems value="#{gender.selectableGenders}" var="g" itemValue="#{g}" itemLabel="#{msg[g.messageKey]}" />
        </h:selectOneMenu>
 </ui:composition>
index a3f11e838bd883c12c1615d62605428a9d6805c7..7c780dd32cdad63e2ddf1d1b1f4ade396690e608 100644 (file)
@@ -31,7 +31,7 @@
                                </div>
 
                                <div class="table_right">
-                                       <h:inputText class="input" id="companyname" size="15" maxlength="255" value="#{customer.companyName}" />
+                                       <h:inputText class="input" id="companyname" size="15" maxlength="255" value="#{customerController.companyName}" />
                                </div>
 
                                <div class="clear"></div>
@@ -43,7 +43,7 @@
                                </div>
 
                                <div class="table_right">
-                                       <h:inputText class="input" id="firstName" size="10" maxlength="255" value="#{customer.firstName}" required="true">
+                                       <h:inputText class="input" id="firstName" size="10" maxlength="255" value="#{customerController.firstName}" required="true">
                                                <f:validator validatorId="NameValidator" />
                                        </h:inputText>
                                </div>
@@ -57,7 +57,7 @@
                                </div>
 
                                <div class="table_right">
-                                       <h:inputText class="input" id="familyName" size="10" maxlength="255" value="#{customer.familyName}" required="true">
+                                       <h:inputText class="input" id="familyName" size="10" maxlength="255" value="#{customerController.familyName}" required="true">
                                                <f:validator validatorId="NameValidator" />
                                        </h:inputText>
                                </div>
@@ -71,7 +71,7 @@
                                </div>
 
                                <div class="table_right">
-                                       <h:inputText class="input" id="street" size="20" maxlength="255" value="#{customer.street}" required="true">
+                                       <h:inputText class="input" id="street" size="20" maxlength="255" value="#{customerController.street}" required="true">
                                                <f:validator validatorId="NameValidator" />
                                        </h:inputText>
                                </div>
@@ -85,7 +85,7 @@
                                </div>
 
                                <div class="table_right">
-                                       <h:inputText class="input" id="houseNumber" size="3" maxlength="5" value="#{customer.houseNumber}" required="true">
+                                       <h:inputText class="input" id="houseNumber" size="3" maxlength="5" value="#{customerController.houseNumber}" required="true">
                                                <f:validateLongRange minimum="1" maximum="500" />
                                        </h:inputText>
                                </div>
@@ -99,7 +99,7 @@
                                </div>
 
                                <div class="table_right">
-                                       <h:inputText class="input" id="zipCode" size="5" maxlength="6" value="#{customer.zipCode}" required="true" />
+                                       <h:inputText class="input" id="zipCode" size="5" maxlength="6" value="#{customerController.zipCode}" required="true" />
                                </div>
 
                                <div class="clear"></div>
                                </div>
 
                                <div class="table_right">
-                                       <h:inputText class="input" id="city" size="10" maxlength="255" value="#{customer.city}" required="true">
+                                       <h:inputText class="input" id="city" size="10" maxlength="255" value="#{customerController.city}" required="true">
                                                <f:validator validatorId="NameValidator" />
                                        </h:inputText>
                                </div>
                                </div>
 
                                <div class="table_right">
-                                       <h:inputText class="input" id="phoneNumber" size="20" maxlength="255" value="#{customer.phoneNumber}" />
+                                       <h:inputText class="input" id="phoneNumber" size="20" maxlength="255" value="#{customerController.phoneNumber}" />
                                </div>
 
                                <div class="clear"></div>
                                </div>
 
                                <div class="table_right">
-                                       <h:inputText class="input" id="faxNumber" size="20" maxlength="255" value="#{customer.faxNumber}" />
+                                       <h:inputText class="input" id="faxNumber" size="20" maxlength="255" value="#{customerController.faxNumber}" />
                                </div>
 
                                <div class="clear"></div>
                                </div>
 
                                <div class="table_right">
-                                       <h:inputText class="input" id="cellphoneNumber" size="20" maxlength="255" value="#{customer.cellphoneNumber}" />
+                                       <h:inputText class="input" id="cellphoneNumber" size="20" maxlength="255" value="#{customerController.cellphoneNumber}" />
                                </div>
 
                                <div class="clear"></div>
index a28447825f484b73586acdd7bbd233d249f87055..3bed98b6fbdbf4bca5ae1e2a01d76be92bdda15b 100644 (file)
@@ -24,7 +24,7 @@
                                                </div>
 
                                                <div class="table_right">
-                                                       <h:inputText class="input" id="emailAddress1" size="20" maxlength="255" value="#{customer.emailAddress}" required="true" />
+                                                       <h:inputText class="input" id="emailAddress1" size="20" maxlength="255" value="#{customerController.emailAddress}" required="true" />
                                                </div>
 
                                                <div class="clear"></div>
@@ -36,7 +36,7 @@
                                                </div>
 
                                                <div class="table_right">
-                                                       <h:inputText class="input" id="emailAddress2" size="20" maxlength="255" value="#{customer.emailAddress}" required="true" />
+                                                       <h:inputText class="input" id="emailAddress2" size="20" maxlength="255" value="#{customerController.emailAddress}" required="true" />
                                                </div>
 
                                                <div class="clear"></div>