]> git.mxchange.org Git - addressbook-war.git/blobdiff - src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java
Don't cherry-pick:
[addressbook-war.git] / src / java / org / mxchange / addressbook / beans / contact / AddressbookAdminContactWebRequestBean.java
index a05174d05fe0b335a756b75833aa4df462aeef1e..11396494db84dc780b5229bd812ec6dd442fab3f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2022 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -18,40 +18,40 @@ package org.mxchange.addressbook.beans.contact;
 
 import java.text.MessageFormat;
 import java.util.Date;
-import java.util.Iterator;
-import javax.annotation.PostConstruct;
+import javax.ejb.EJB;
 import javax.enterprise.context.RequestScoped;
 import javax.enterprise.event.Event;
+import javax.enterprise.event.Observes;
 import javax.enterprise.inject.Any;
-import javax.faces.context.FacesContext;
-import javax.faces.view.facelets.FaceletException;
+import javax.faces.FacesException;
 import javax.inject.Inject;
 import javax.inject.Named;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import org.mxchange.addressbook.beans.BaseAddressbookController;
-import org.mxchange.addressbook.beans.helper.AddressbookWebRequestHelperController;
-import org.mxchange.jcontacts.contact.AdminContactSessionBeanRemote;
-import org.mxchange.jcontacts.contact.Contact;
-import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
-import org.mxchange.jcontacts.contact.ContactUtils;
-import org.mxchange.jcontacts.contact.UserContact;
-import org.mxchange.jcontacts.contact.title.PersonalTitle;
+import org.mxchange.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.addressbook.beans.contact.list.AddressbookContactListWebViewController;
 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
+import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent;
+import org.mxchange.jcontacts.events.contact.deleted.AdminDeletedContactEvent;
+import org.mxchange.jcontacts.events.contact.deleted.ObservableAdminDeletedContactEvent;
 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
 import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException;
-import org.mxchange.jcountry.data.Country;
-import org.mxchange.jphone.phonenumbers.DialableNumber;
-import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
-import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
-import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
-import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
-import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
+import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
+import org.mxchange.jcontacts.model.contact.AdminContactSessionBeanRemote;
+import org.mxchange.jcontacts.model.contact.Contact;
+import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote;
+import org.mxchange.jcontacts.model.contact.UserContact;
+import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
+import org.mxchange.jcontacts.model.utils.ContactUtils;
+import org.mxchange.jcountry.model.data.Country;
+import org.mxchange.jphone.model.phonenumbers.DialableNumber;
+import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
+import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
+import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
+import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
 
 /**
  * An administrative user bean (controller)
@@ -60,7 +60,7 @@ import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
  */
 @Named ("adminContactController")
 @RequestScoped
-public class AddressbookAdminContactWebRequestBean extends BaseAddressbookController implements AddressbookAdminContactWebRequestController {
+public class AddressbookAdminContactWebRequestBean extends BaseAddressbookBean implements AddressbookAdminContactWebRequestController {
 
        /**
         * Serial number
@@ -82,14 +82,9 @@ public class AddressbookAdminContactWebRequestBean extends BaseAddressbookContro
        /**
         * Administrative contact EJB
         */
+       @EJB (lookup = "java:global/addressbook-ejb/adminContact!org.mxchange.jcontacts.model.contact.AdminContactSessionBeanRemote")
        private AdminContactSessionBeanRemote adminContactBean;
 
-       /**
-        * Bean helper instance
-        */
-       @Inject
-       private AddressbookWebRequestHelperController beanHelper;
-
        /**
         * Birth day
         */
@@ -106,15 +101,20 @@ public class AddressbookAdminContactWebRequestBean extends BaseAddressbookContro
        private String comment;
 
        /**
-        * Remote contact bean
+        * Current contact instance
         */
+       private Contact contact;
+
+       /**
+        * EJB for general contact purposes
+        */
+       @EJB (lookup = "java:global/addressbook-ejb/contact!org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote")
        private ContactSessionBeanRemote contactBean;
 
        /**
-        * General contact controller
+        * Country instance
         */
-       @Inject
-       private AddressbookContactWebSessionController contactController;
+       private Country contactCountry;
 
        /**
         * Contact id
@@ -122,9 +122,17 @@ public class AddressbookAdminContactWebRequestBean extends BaseAddressbookContro
        private Long contactId;
 
        /**
-        * Country instance
+        * An instance of a contact list controller
         */
-       private Country contactCountry;
+       @Inject
+       private AddressbookContactListWebViewController contactListController;
+
+       /**
+        * Event being fired when an administrator has deleted a contact
+        */
+       @Any
+       @Inject
+       private Event<ObservableAdminDeletedContactEvent> deletedContactEvent;
 
        /**
         * Email address
@@ -182,7 +190,7 @@ public class AddressbookAdminContactWebRequestBean extends BaseAddressbookContro
        private boolean isLandLineUnlinked;
 
        /**
-        * Whether a cmobile entry has been unlinked
+        * Whether a mobile entry has been unlinked
         */
        private boolean isMobileNumberUnlinked;
 
@@ -254,10 +262,8 @@ public class AddressbookAdminContactWebRequestBean extends BaseAddressbookContro
        /**
         * Adds contact data to database and redirects on success. If the contact is
         * already found, a proper exception is thrown.
-        * <p>
-        * @return Redirect outcome
         */
-       public String addContact () {
+       public void addContact () {
                // Are all minimum fields set?
                if (this.getPersonalTitle() == null) {
                        // Throw NPE
@@ -277,24 +283,24 @@ public class AddressbookAdminContactWebRequestBean extends BaseAddressbookContro
                }
 
                // Create new contact instance
-               Contact contact = this.createContactInstance();
+               final Contact createdContact = this.createContactInstance();
 
                // Default is not same contact
-               if (this.isSameContactFound(contact)) {
+               if (this.contactListController.isContactFound(createdContact)) {
                        // Already registered
-                       throw new FaceletException(new ContactAlreadyAddedException(contact));
+                       throw new FacesException(new ContactAlreadyAddedException(createdContact));
                }
 
                // Init contact
-               Contact updatedContact;
+               final Contact updatedContact;
 
                // Try to call EJB
                try {
                        // Call EJB
-                       updatedContact = this.adminContactBean.addContact(contact);
+                       updatedContact = this.adminContactBean.addContact(createdContact);
                } catch (final ContactAlreadyAddedException ex) {
                        // Throw again
-                       throw new FaceletException(ex);
+                       throw new FacesException(ex);
                }
 
                // Fire event
@@ -302,72 +308,83 @@ public class AddressbookAdminContactWebRequestBean extends BaseAddressbookContro
 
                // Clear this bean
                this.clear();
-
-               // Return outcome
-               return "admin_list_contact"; //NOI18N
        }
 
-       @Override
-       public void copyContactToController (final Contact contact) {
+       /**
+        * Observer for events being fired when a bean helper has successfully
+        * created a contact instance.
+        * <p>
+        * @param event Event being fired
+        */
+       public void afterCreatedContactEvent (@Observes final ObservableCreatedContactEvent event) {
                // Log message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::copyContactToController(): contact={0} - CALLED!", contact)); //NOI18N
+               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::afterCreatedContactEvent(): contact={0} - CALLED!", contact)); //NOI18N
 
-               // The contact instance must be valid
-               if (null == contact) {
+               // The event instance must be valid
+               if (null == event) {
                        // Throw NPE again
-                       throw new NullPointerException("contact is null"); //NOI18N
-               } else if (contact.getContactId() == null) {
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getCreatedContact() == null) {
                        // Throw NPE again
-                       throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
-               } else if (contact.getContactId() < 1) {
+                       throw new NullPointerException("event.createdContact is null"); //NOI18N
+               } else if (event.getCreatedContact().getContactId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.createdContact.contactId is null"); //NOI18N
+               } else if (event.getCreatedContact().getContactId() < 1) {
                        // Not valid
-                       throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
+                       throw new IllegalStateException(MessageFormat.format("event.createdContact.contactId={0} is not valid.", event.getCreatedContact().getContactId())); //NOI18N
                }
 
+               // Set contact for e.g. delete method
+               this.setContact(event.getCreatedContact());
+
+               // Get contact instance from event
+               final Contact createdContact = event.getCreatedContact();
+
                // Set all fields: contact
-               this.setContactId(contact.getContactId());
-               this.setAcademicTitle(contact.getContactTitle());
-               this.setBirthday(contact.getContactBirthday());
-               this.setCity(contact.getContactCity());
-               this.setComment(contact.getContactComment());
-               this.setContactCountry(contact.getContactCountry());
-               this.setEmailAddress(contact.getContactEmailAddress());
-               this.setFamilyName(contact.getContactFamilyName());
-               this.setFirstName(contact.getContactFirstName());
-               this.setPersonalTitle(contact.getContactPersonalTitle());
-               this.setHouseNumber(contact.getContactHouseNumber());
-               this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
-               this.setStreet(contact.getContactStreet());
-               this.setZipCode(contact.getContactZipCode());
+               this.setContactId(createdContact.getContactId());
+               this.setAcademicTitle(createdContact.getContactTitle());
+               this.setBirthday(createdContact.getContactBirthday());
+               this.setCity(createdContact.getContactCity());
+               this.setComment(createdContact.getContactComment());
+               this.setContactCountry(createdContact.getContactCountry());
+               this.setEmailAddress(createdContact.getContactEmailAddress());
+               this.setFamilyName(createdContact.getContactFamilyName());
+               this.setFirstName(createdContact.getContactFirstName());
+               this.setPersonalTitle(createdContact.getContactPersonalTitle());
+               this.setHouseNumber(createdContact.getContactHouseNumber());
+               this.setHouseNumberExtension(createdContact.getContactHouseNumberExtension());
+               this.setStreet(createdContact.getContactStreet());
+               this.setZipCode(createdContact.getContactZipCode());
 
                // Is the cell phone set?
-               if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
+               if (createdContact.getContactMobileNumber() instanceof DialableMobileNumber) {
                        // ... cmobile data
-                       this.setMobileId(contact.getContactMobileNumber().getPhoneId());
-                       this.setMobileProvider(contact.getContactMobileNumber().getMobileProvider());
-                       this.setMobileNumber(contact.getContactMobileNumber().getPhoneNumber());
+                       this.setMobileId(createdContact.getContactMobileNumber().getMobileId());
+                       this.setMobileProvider(createdContact.getContactMobileNumber().getMobileProvider());
+                       this.setMobileNumber(createdContact.getContactMobileNumber().getMobileNumber());
                }
 
                // Is the fax set?
-               if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
+               if (createdContact.getContactFaxNumber() instanceof DialableFaxNumber) {
                        // ... fax data
-                       this.setFaxId(contact.getContactFaxNumber().getPhoneId());
-                       this.setFaxAreaCode(contact.getContactFaxNumber().getPhoneAreaCode());
-                       this.setFaxCountry(contact.getContactFaxNumber().getPhoneCountry());
-                       this.setFaxNumber(contact.getContactFaxNumber().getPhoneNumber());
+                       this.setFaxId(createdContact.getContactFaxNumber().getPhoneId());
+                       this.setFaxAreaCode(createdContact.getContactFaxNumber().getPhoneAreaCode());
+                       this.setFaxCountry(createdContact.getContactFaxNumber().getPhoneCountry());
+                       this.setFaxNumber(createdContact.getContactFaxNumber().getPhoneNumber());
                }
 
                // Is the land-line number set?
-               if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
+               if (createdContact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
                        // .. land-line data
-                       this.setLandLineId(contact.getContactLandLineNumber().getPhoneId());
-                       this.setLandLineAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode());
-                       this.setLandLineCountry(contact.getContactLandLineNumber().getPhoneCountry());
-                       this.setLandLineNumber(contact.getContactLandLineNumber().getPhoneNumber());
+                       this.setLandLineId(createdContact.getContactLandLineNumber().getPhoneId());
+                       this.setLandLineAreaCode(createdContact.getContactLandLineNumber().getPhoneAreaCode());
+                       this.setLandLineCountry(createdContact.getContactLandLineNumber().getPhoneCountry());
+                       this.setLandLineNumber(createdContact.getContactLandLineNumber().getPhoneNumber());
                }
 
                // Log message
-               //* NOISY-DEBUG: */ System.out.println("AdminContactController::copyContactToController(): EXIT!"); //NOI18N
+               //* NOISY-DEBUG: */ System.out.println("AdminContactController::afterCreatedContactEvent(): EXIT!"); //NOI18N
        }
 
        @Override
@@ -388,30 +405,60 @@ public class AddressbookAdminContactWebRequestBean extends BaseAddressbookContro
                } else if (this.getFamilyName().isEmpty()) {
                        // Empty string
                        throw new IllegalStateException("familyName is empty"); //NOI18N
+               } else if (this.getContactCountry() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("contactCountry is null"); //NOI18N
+               } else if (this.getContactCountry().getCountryId() == null) {
+                       // Throw it again
+                       throw new NullPointerException("contactCountry.countryId is null"); //NOI18N
+               } else if (this.getContactCountry().getCountryId() < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("contactCountry.countryId={0} is invalid", this.getContactCountry().getCountryId())); //NOI18N
                }
 
                // Generate phone number
-               DialableLandLineNumber landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
-               DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
-               DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
+               DialableLandLineNumber landLine = null;
+               DialableMobileNumber mobile = null;
+               DialableFaxNumber fax = null;
+
+               // Are all fields set?
+               if (this.getLandLineAreaCode() != null && this.getLandLineCountry() instanceof Country && this.getLandLineNumber() != null) {
+                       // Init instance
+                       landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
+               }
 
-               // Create new instance
-               Contact contact = new UserContact(this.getPersonalTitle(), this.getFirstName(), this.getFamilyName());
+               // Are all fields set?
+               if (this.getMobileProvider() instanceof MobileProvider && this.getMobileNumber() != null) {
+                       // Initialize instance
+                       mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
+               }
 
-               // Add all others
-               contact.setContactTitle(this.getAcademicTitle());
-               contact.setContactBirthday(this.getBirthday());
-               contact.setContactStreet(this.getStreet());
-               contact.setContactHouseNumber(this.getHouseNumber());
-               contact.setContactZipCode(this.getZipCode());
-               contact.setContactCity(this.getCity());
-               contact.setContactCountry(this.getContactCountry());
-               contact.setContactEmailAddress(this.getEmailAddress());
-               contact.setContactBirthday(this.getBirthday());
-               contact.setContactComment(this.getComment());
+               // Are all fields set?
+               if (this.getFaxAreaCode() != null && this.getFaxCountry() instanceof Country && this.getFaxNumber() != null) {
+                       // Initialize instance
+                       fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
+               }
 
-               // Set ownContact
-               contact.setContactOwnContact(Boolean.TRUE);
+               // Create new instance
+               final Contact localContact = new UserContact(
+                                         this.getPersonalTitle(),
+                                         this.getFirstName(),
+                                         this.getFamilyName(),
+                                         this.getContactCountry(),
+                                         Boolean.FALSE,
+                                         this.getStreet(),
+                                         this.getHouseNumber(),
+                                         this.getHouseNumberExtension(),
+                                         this.getZipCode(),
+                                         this.getCity(),
+                                         this.getEmailAddress(),
+                                         this.getAcademicTitle(),
+                                         this.getBirthday(),
+                                         this.getComment()
+                         );
+
+               // Add missing fields
+               localContact.setContactId(this.getContactId());
 
                // Don't set null or wrong references
                if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
@@ -421,17 +468,17 @@ public class AddressbookAdminContactWebRequestBean extends BaseAddressbookContro
                                throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
                        } else if (landLine.getPhoneAreaCode() < 1) {
                                // Abort here
-                               throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
+                               throw new IllegalStateException("phone.phoneAreaCode is zero or below."); //NOI18N
                        } else if (landLine.getPhoneNumber() == null) {
                                // Is null
                                throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
                        } else if (landLine.getPhoneNumber() < 1) {
                                // Abort here
-                               throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
+                               throw new IllegalStateException("phone.phoneNumber is zero or below."); //NOI18N
                        }
 
                        // Set phone number
-                       contact.setContactLandLineNumber(landLine);
+                       localContact.setContactLandLineNumber(landLine);
                }
 
                // Don't set null or wrong references
@@ -442,73 +489,109 @@ public class AddressbookAdminContactWebRequestBean extends BaseAddressbookContro
                                throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
                        } else if (fax.getPhoneAreaCode() < 1) {
                                // Abort here
-                               throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
+                               throw new IllegalStateException("fax.phoneAreaCode is zero or below."); //NOI18N
                        } else if (fax.getPhoneNumber() == null) {
                                // Is null
                                throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
                        } else if (fax.getPhoneNumber() < 1) {
                                // Abort here
-                               throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
+                               throw new IllegalStateException("fax.phoneNumber is zero or below."); //NOI18N
                        }
 
                        // Set fax number
-                       contact.setContactFaxNumber(fax);
+                       localContact.setContactFaxNumber(fax);
                }
 
                // Is the provider set?
                if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
                        // Is the number set?
-                       if (mobile.getPhoneNumber() == null) {
+                       if (mobile.getMobileNumber() == null) {
                                // Is null
                                throw new NullPointerException("cmobile.phoneNumber is null"); //NOI18N
-                       } else if (mobile.getPhoneNumber() < 1) {
+                       } else if (mobile.getMobileNumber() < 1) {
                                // Abort here
-                               throw new IllegalArgumentException("cmobile.phoneNumber is zero or below."); //NOI18N
+                               throw new IllegalStateException("cmobile.phoneNumber is zero or below."); //NOI18N
                        }
 
                        // Set cmobile number
-                       contact.setContactMobileNumber(mobile);
+                       localContact.setContactMobileNumber(mobile);
                }
 
                // Return it
-               return contact;
+               return localContact;
+       }
+
+       /**
+        * Deletes currently chosen contact and returns to list view
+        *
+        * @return
+        */
+       public String deleteContactData () {
+               // Is contact set?
+               if (this.getContact() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("this.contact is null");
+               } else if (this.getContact().getContactId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("this.contact.contactId is null");
+               } else if (this.getContact().getContactId() < 1) {
+                       // Throw IAE
+                       throw new NullPointerException(MessageFormat.format("this.contact.contactId={0} is not valid.", this.getContact().getContactId()));
+               }
+
+               try {
+                       // Invoke EJB
+                       this.adminContactBean.deleteContactData(this.getContact());
+               } catch (final ContactNotFoundException ex) {
+                       // Throw it again
+                       throw new FacesException(ex);
+               }
+
+               // Fire event
+               this.deletedContactEvent.fire(new AdminDeletedContactEvent(this.getContact()));
+
+               // Return to list view
+               return "admin_list_contacts";
        }
 
        /**
         * Edits currently loaded contact's data in database.
-        * <p>
-        * @return Redirect outcome
         */
-       public String editContactData () {
+       public void editContactData () {
                // Get contact instance
-               Contact contact = this.beanHelper.getContact();
+               final Contact createdContact = this.createContactInstance();
 
                // Check if contact instance is in helper and valid
-               if (null == contact) {
+               if (null == createdContact) {
                        // Throw NPE
                        throw new NullPointerException("beanHelper.contact is null"); //NOI18N
-               } else if (contact.getContactId() == null) {
+               } else if (createdContact.getContactId() == null) {
                        // Throw NPE again
-                       throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N //NOI18N
-               } else if (contact.getContactId() < 1) {
+                       throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N
+               } else if (createdContact.getContactId() < 1) {
                        // Invalid id
-                       throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
+                       throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", createdContact.getContactId())); //NOI18N
                }
 
                // Update all data in contact
-               this.updateContactData(contact);
+               this.updateContactData(createdContact);
+
+               // Init updated contact instance
+               final Contact updatedContact;
 
-               // Call EJB for updating contact data
-               Contact updatedContact = this.contactBean.updateContactData(contact, this.isMobileNumberUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
+               try {
+                       // Call EJB for updating contact data
+                       updatedContact = this.contactBean.updateContactData(createdContact, this.isMobileNumberUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
+               } catch (final ContactNotFoundException ex) {
+                       // Throw as a cause
+                       throw new FacesException(ex);
+               }
 
                // Fire event
                this.updatedContactEvent.fire(new AdminUpdatedContactEvent(updatedContact));
 
                // Clear bean
                this.clear();
-
-               // Return to contact list (for now)
-               return "admin_list_contact"; //NOI18N
        }
 
        /**
@@ -526,12 +609,12 @@ public class AddressbookAdminContactWebRequestBean extends BaseAddressbookContro
                }
 
                // Get all data
-               String number = String.format(
-                          "%s%d%d", //NOI18N
-                          mobileNumber.getMobileProvider().getProviderCountry().getCountryExternalDialPrefix(),
-                          mobileNumber.getMobileProvider().getProviderDialPrefix(),
-                          mobileNumber.getPhoneNumber()
-          );
+               final String number = String.format(
+                                        "%s%d%d", //NOI18N
+                                        mobileNumber.getMobileProvider().getProviderCountry().getCountryExternalDialPrefix(),
+                                        mobileNumber.getMobileProvider().getProviderDialPrefix(),
+                                        mobileNumber.getMobileNumber()
+                        );
 
                // Return it
                return number;
@@ -553,12 +636,12 @@ public class AddressbookAdminContactWebRequestBean extends BaseAddressbookContro
                }
 
                // Generate it
-               String number = String.format(
-                          "%s%d%d", //NOI18N
-                          phoneNumber.getPhoneCountry().getCountryExternalDialPrefix(),
-                          phoneNumber.getPhoneAreaCode(),
-                          phoneNumber.getPhoneNumber()
-          );
+               final String number = String.format(
+                                        "%s%d%d", //NOI18N
+                                        phoneNumber.getPhoneCountry().getCountryExternalDialPrefix(),
+                                        phoneNumber.getPhoneAreaCode(),
+                                        phoneNumber.getPhoneNumber()
+                        );
 
                // Return it
                return number;
@@ -639,32 +722,21 @@ public class AddressbookAdminContactWebRequestBean extends BaseAddressbookContro
        }
 
        /**
-        * Getter for contact id
+        * Getter for contact instance
         * <p>
-        * @return Contact id
+        * @return Contact instance
         */
-       public Long getContactId () {
-               return this.contactId;
+       public Contact getContact () {
+               return this.contact;
        }
 
        /**
-        * Setter for contact id
+        * Setter for contact instance
         * <p>
-        * @param contactId Contact id
+        * @param contact Contact instance
         */
-       public void setContactId (final Long contactId) {
-               this.contactId = contactId;
-       }
-
-       @Override
-       public String getControllerType () {
-               return "admin"; //NOI18N
-       }
-
-       @Override
-       @Deprecated
-       public void setControllerType (final String controllerType) {
-               throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
+       public void setContact (final Contact contact) {
+               this.contact = contact;
        }
 
        /**
@@ -685,6 +757,29 @@ public class AddressbookAdminContactWebRequestBean extends BaseAddressbookContro
                this.contactCountry = contactCountry;
        }
 
+       /**
+        * Getter for contact id
+        * <p>
+        * @return Contact id
+        */
+       public Long getContactId () {
+               return this.contactId;
+       }
+
+       /**
+        * Setter for contact id
+        * <p>
+        * @param contactId Contact id
+        */
+       public void setContactId (final Long contactId) {
+               this.contactId = contactId;
+       }
+
+       @Override
+       public String getControllerType () {
+               return "admin"; //NOI18N
+       }
+
        /**
         * Getter for email address
         * <p>
@@ -1028,40 +1123,6 @@ public class AddressbookAdminContactWebRequestBean extends BaseAddressbookContro
                this.zipCode = zipCode;
        }
 
-       /**
-        * Post-initialization of this class
-        */
-       @PostConstruct
-       public void init () {
-               // Try it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup
-                       this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/addressbook-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
-
-                       // Try to lookup (administative)
-                       this.adminContactBean = (AdminContactSessionBeanRemote) context.lookup("java:global/addressbook-ejb/adminContact!org.mxchange.jcontacts.contact.AdminContactSessionBeanRemote"); //NOI18N
-               } catch (final NamingException e) {
-                       // Throw again
-                       throw new FaceletException(e);
-               }
-       }
-
-       @Override
-       @Deprecated
-       public boolean isPersonalTitleRequired () {
-               // Get context parameter
-               String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_admin_personal_title_enabled"); //NOI18N
-
-               // Is it set?
-               boolean isRequired = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
-
-               // Return value
-               return isRequired;
-       }
-
        @Override
        public void validateContactData () {
                if (this.getPersonalTitle() == null) {
@@ -1093,6 +1154,8 @@ public class AddressbookAdminContactWebRequestBean extends BaseAddressbookContro
         */
        private void clear () {
                // Clear all data
+               this.setContact(null);
+
                // - personal data
                this.setAcademicTitle(null);
                this.setFirstName(null);
@@ -1120,37 +1183,6 @@ public class AddressbookAdminContactWebRequestBean extends BaseAddressbookContro
                this.setComment(null);
        }
 
-       /**
-        * Checks whether the given contact is found
-        * <p>
-        * @param contact Contact inastance
-        *
-        * @return Wether contact has been found
-        */
-       private boolean isSameContactFound (final Contact contact) {
-               // Default is not found
-               boolean IsFound = false;
-
-               // Get iterator
-               Iterator<Contact> iterator = this.contactController.allContacts().iterator();
-
-               // Loop through all
-               while (iterator.hasNext()) {
-                       // Get next contact
-                       Contact next = iterator.next();
-
-                       // Is the same?
-                       if (ContactUtils.isSameContact(contact, next)) {
-                               // Yes, then abort loop
-                               IsFound = false;
-                               break;
-                       }
-               }
-
-               // Return status
-               return IsFound;
-       }
-
        /**
         * Updates all data in contact instance.
         * <p>
@@ -1163,7 +1195,7 @@ public class AddressbookAdminContactWebRequestBean extends BaseAddressbookContro
                        throw new NullPointerException("contact is null"); //NOI18N
                } else if (contact.getContactId() == null) {
                        // Throw NPE again
-                       throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
+                       throw new NullPointerException("contact.contactId is null"); //NOI18N
                } else if (contact.getContactId() < 1) {
                        // Invalid id
                        throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N