From ee6c37854a12b32bfdbf533bd29d9783e481e34e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 27 Apr 2016 08:52:40 +0200 Subject: [PATCH] Continued with contacts: - added hasContacts() / allContacts() - listing of contacts started, maybe later add a method that checks where the contact is being used and returns a message key? MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- ...AddressbookAdminContactWebRequestBean.java | 44 +++++-------------- .../AddressbookContactWebSessionBean.java | 13 +++--- ...ddressbookContactWebSessionController.java | 8 ++++ web/admin/contact/admin_contact_list.xhtml | 2 +- 4 files changed, 27 insertions(+), 40 deletions(-) diff --git a/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java index 3e1826f0..6c1a4831 100644 --- a/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java @@ -112,6 +112,12 @@ public class AddressbookAdminContactWebRequestBean implements AddressbookAdminCo */ private final ContactSessionBeanRemote contactBean; + /** + * General contact controller + */ + @Inject + private AddressbookContactWebSessionController contactController; + /** * Contact id */ @@ -292,39 +298,6 @@ public class AddressbookAdminContactWebRequestBean implements AddressbookAdminCo return this.contactController.allContacts(); } - @Override - public String changeContactData () { - // Get contact instance - Contact contact = this.adminHelper.getContact(); - - // Default is not same contact - if (this.isSameContactFound(contact)) { - // Already registered - throw new FaceletException(new ContactAlreadyAddedException(contact)); - } - - // Init contact - Contact updatedContact; - - // Try to call EJB - try { - // Call EJB - updatedContact = this.contactBean.addContact(contact); - } catch (final ContactAlreadyAddedException ex) { - // Throw again - throw new FaceletException(ex); - } - - // Fire event - this.addedContactEvent.fire(new AdminContactAddedEvent(updatedContact)); - - // Clear this bean - this.clear(); - - // Return outcome - return "admin_list_contact"; //NOI18N - } - @Override public void copyContactToController (final Contact contact) { // The contact instance must be valid @@ -659,6 +632,11 @@ public class AddressbookAdminContactWebRequestBean implements AddressbookAdminCo this.zipCode = zipCode; } + @Override + public boolean hasContacts () { + return (!this.allContacts().isEmpty()); + } + /** * Post-initialization of this class */ diff --git a/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java index e06149a3..310508de 100644 --- a/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java @@ -229,7 +229,7 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe @Override public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) { // Trace message - System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N // event should not be null if (null == event) { @@ -275,7 +275,7 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe @Override public void afterRegistrationEvent (final @Observes UserRegisteredEvent event) { // Trace message - System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N // event should not be null if (null == event) { @@ -296,7 +296,7 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe Contact registeredContact = event.getRegisteredUser().getUserContact(); // Debug message - System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: registeredContact={0}", registeredContact)); //NOI18N + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: registeredContact={0}", registeredContact)); //NOI18N // Copy all data from registered->user this.copyContact(registeredContact); @@ -308,13 +308,13 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe this.clear(); // Trace message - System.out.println("ContactWebBean:afterRegistration: EXIT!"); //NOI18N + //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterRegistration: EXIT!"); //NOI18N } @Override public void afterUserLogin (final @Observes UserLoggedInEvent event) { // Trace message - System.out.println(MessageFormat.format("ContactWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N // event should not be null if (null == event) { @@ -335,10 +335,11 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe this.copyContact(event.getLoggedInUser().getUserContact()); // Trace message - System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N + //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N } @SuppressWarnings ("ReturnOfCollectionOrArrayField") + @Override public List allContacts () { return this.contactList; } diff --git a/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionController.java b/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionController.java index 39998c6c..378137d1 100644 --- a/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionController.java +++ b/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionController.java @@ -18,6 +18,7 @@ package org.mxchange.addressbook.beans.contact; import java.io.Serializable; import java.util.Date; +import java.util.List; import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jcontacts.contact.gender.Gender; import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent; @@ -39,6 +40,13 @@ public interface AddressbookContactWebSessionController extends Serializable { */ public static final Integer MINIMUM_PASSWORD_LENGTH = 5; + /** + * Returns a list of all found contacts + *

+ * @return A list of all contacts. + */ + List allContacts(); + /** * Updates all data from bean in given contact instance *

diff --git a/web/admin/contact/admin_contact_list.xhtml b/web/admin/contact/admin_contact_list.xhtml index b496a407..dca2708a 100644 --- a/web/admin/contact/admin_contact_list.xhtml +++ b/web/admin/contact/admin_contact_list.xhtml @@ -1,4 +1,4 @@ -_ +