From: Roland Haeder Date: Thu, 15 Oct 2015 15:40:49 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=43af64029f2991850d1f187ee6003fe8f6c49025;p=addressbook-war.git Continued: - use isUserLoggedIn() not userLoggedIn in templates, else it won't work! - added bean method isGuest() - ui:fragment or f:outputText? :-( - added bean method countAllUserSharedAddressbooks() - showed count of shared address books to guests --- diff --git a/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java b/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java index d9c19638..e69455e7 100644 --- a/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java +++ b/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java @@ -43,7 +43,7 @@ import org.mxchange.addressbook.model.addressbook.status.AddressbokStatus; import org.mxchange.jusercore.model.user.User; /** - * A user bean (controller) + * An address book bean (controller) *

* @author Roland Haeder */ @@ -61,6 +61,11 @@ public class AddressbookWebBean implements AddressbookWebController { */ private AddressbookSessionBeanRemote addressbookBean; + /** + * When this address book has been created + */ + private Calendar addressbookCreated; + /** * Address book id number (from URL for example) */ @@ -71,11 +76,6 @@ public class AddressbookWebBean implements AddressbookWebController { */ private String addressbookName; - /** - * When this address book has been created - */ - private Calendar addressbookCreated; - /** * Who owns this address book */ @@ -157,6 +157,36 @@ public class AddressbookWebBean implements AddressbookWebController { } } + @Override + public void afterAddressbookLoaded (final @Observes AddressbookLoadedEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); + } else if (event.getAddressbook() == null) { + // Throw NPE again + throw new NullPointerException("event.addressbook is null"); + } else if (event.getAddressbook().getAddressbookId() == null) { + // And again a NPE + throw new NullPointerException("event.addressbook.addressbookId is null"); + } else if (event.getAddressbook().getAddressbookId() < 1) { + // Invalid id number + throw new IllegalArgumentException("Address book instance " + event.getAddressbook() + " has invalid id number: " + event.getAddressbook().getAddressbookId()); + } else if (event.getAddressbook().getAddressbookUser() == null) { + // One more NPE ... + throw new NullPointerException("event.addressbook.addressbookUser is null"); + } + + // Get address book instance + Addressbook addressbook = event.getAddressbook(); + + // Set address book data + this.setAddressbookId(addressbook.getAddressbookId()); + this.setAddressbookName(addressbook.getAddressbookName()); + this.setAddressbookUser(addressbook.getAddressbookUser()); + this.setAddressbookCreated(addressbook.getAddressbookCreated()); + } + @Override public List allAddressbooks () { // Is the user logged in? @@ -197,6 +227,12 @@ public class AddressbookWebBean implements AddressbookWebController { return Collections.unmodifiableList(this.sharedAddressbooks); } + @Override + public Integer countAllUserSharedAddressbooks (final User user) { + // Call EJB + return this.addressbookBean.countAllUserSharedAddressbooks(user); + } + @Override public Calendar getAddressbookCreated () { return this.addressbookCreated; @@ -288,34 +324,4 @@ public class AddressbookWebBean implements AddressbookWebController { // Return status return isFound; } - - @Override - public void afterAddressbookLoaded (final @Observes AddressbookLoadedEvent event) { - // event should not be null - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); - } else if (event.getAddressbook() == null) { - // Throw NPE again - throw new NullPointerException("event.addressbook is null"); - } else if (event.getAddressbook().getAddressbookId() == null) { - // And again a NPE - throw new NullPointerException("event.addressbook.addressbookId is null"); - } else if (event.getAddressbook().getAddressbookId() < 1) { - // Invalid id number - throw new IllegalArgumentException("Address book instance " + event.getAddressbook() + " has invalid id number: " + event.getAddressbook().getAddressbookId()); - } else if (event.getAddressbook().getAddressbookUser() == null) { - // One more NPE ... - throw new NullPointerException("event.addressbook.addressbookUser is null"); - } - - // Get address book instance - Addressbook addressbook = event.getAddressbook(); - - // Set address book data - this.setAddressbookId(addressbook.getAddressbookId()); - this.setAddressbookName(addressbook.getAddressbookName()); - this.setAddressbookUser(addressbook.getAddressbookUser()); - this.setAddressbookCreated(addressbook.getAddressbookCreated()); - } } diff --git a/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebController.java b/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebController.java index 463e1a07..f1cf0c45 100644 --- a/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebController.java +++ b/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebController.java @@ -26,7 +26,7 @@ import org.mxchange.addressbook.model.addressbook.shared.ShareableAddressbook; import org.mxchange.jusercore.model.user.User; /** - * An interface for user beans + * An interface for address book beans *

* @author Roland Haeder */ @@ -152,5 +152,14 @@ public interface AddressbookWebController extends Serializable { *

* @param event Event with address book instance */ - public void afterAddressbookLoaded (final AddressbookLoadedEvent event); + void afterAddressbookLoaded (final AddressbookLoadedEvent event); + + /** + * Count all shared address books by given user id + *

+ * @param user User instance to look for + *

+ * @return Count of user's shared address books + */ + Integer countAllUserSharedAddressbooks (final User user); } diff --git a/src/java/org/mxchange/addressbook/beans/login/UserLoginWebBean.java b/src/java/org/mxchange/addressbook/beans/login/UserLoginWebBean.java index ffdf341b..c90b8b7f 100644 --- a/src/java/org/mxchange/addressbook/beans/login/UserLoginWebBean.java +++ b/src/java/org/mxchange/addressbook/beans/login/UserLoginWebBean.java @@ -16,7 +16,6 @@ */ package org.mxchange.addressbook.beans.login; -import java.text.MessageFormat; import java.util.Objects; import javax.enterprise.context.SessionScoped; import javax.faces.view.facelets.FaceletException; @@ -72,6 +71,11 @@ public class UserLoginWebBean implements UserLoginWebController { @Inject private UserWebController userController; + /** + * Flag whether the user has logged-in, set only from inside + */ + private boolean userLoggedIn; + /** * Default constructor */ @@ -134,12 +138,23 @@ public class UserLoginWebBean implements UserLoginWebController { this.templateType = templateType; } + @Override + public boolean isGuest () { + return (!this.isUserLoggedIn()); + } + @Override public boolean isUserLoggedIn () { // Trace message - System.out.println(MessageFormat.format("UserLoginWebBean:isUserLoggedIn: this.loggedInUser={0},this.templateType={1} - CALLED!", this.getLoggedInUser(), this.getTemplateType())); + // NOISY: System.out.println(MessageFormat.format("UserLoginWebBean:isUserLoggedIn: this.loggedInUser={0},this.templateType={1} - CALLED!", this.getLoggedInUser(), this.getTemplateType())); // Compare instance - return ((this.getLoggedInUser() instanceof User) && (Objects.equals(this.getLoggedInUser().getUserAccountStatus(), UserAccountStatus.CONFIRMED))); + this.userLoggedIn = ((this.getLoggedInUser() instanceof User) && (Objects.equals(this.getLoggedInUser().getUserAccountStatus(), UserAccountStatus.CONFIRMED))); + + // Trace message + // NOISY: System.out.println(MessageFormat.format("UserLoginWebBean:isUserLoggedIn: this.userLoggedIn={0} - EXIT!", this.userLoggedIn)); + + // Return it + return this.userLoggedIn; } } diff --git a/src/java/org/mxchange/addressbook/beans/login/UserLoginWebController.java b/src/java/org/mxchange/addressbook/beans/login/UserLoginWebController.java index 4482179b..507c8dbd 100644 --- a/src/java/org/mxchange/addressbook/beans/login/UserLoginWebController.java +++ b/src/java/org/mxchange/addressbook/beans/login/UserLoginWebController.java @@ -67,4 +67,11 @@ public interface UserLoginWebController extends Serializable { * @return Whether the user is logged-in */ boolean isUserLoggedIn (); + + /** + * Is this truly a guest? + *

+ * @return Whether the user is truly a guest + */ + boolean isGuest (); } diff --git a/web/WEB-INF/templates/login/login_base.tpl b/web/WEB-INF/templates/login/login_base.tpl index b8139383..abd205b7 100644 --- a/web/WEB-INF/templates/login/login_base.tpl +++ b/web/WEB-INF/templates/login/login_base.tpl @@ -1,6 +1,6 @@ diff --git a/web/login/login_list_sharing_addressbooks.xhtml b/web/login/login_list_sharing_addressbooks.xhtml index d2064dd4..471a1f18 100644 --- a/web/login/login_list_sharing_addressbooks.xhtml +++ b/web/login/login_list_sharing_addressbooks.xhtml @@ -21,13 +21,13 @@ - + Here goes your content. - + - + - + diff --git a/web/login/login_show_addressbook.xhtml b/web/login/login_show_addressbook.xhtml index 27c9e27d..63cbdbde 100644 --- a/web/login/login_show_addressbook.xhtml +++ b/web/login/login_show_addressbook.xhtml @@ -53,12 +53,13 @@

diff --git a/web/user/user_list.xhtml b/web/user/user_list.xhtml index 9ccd8732..a10bcb50 100644 --- a/web/user/user_list.xhtml +++ b/web/user/user_list.xhtml @@ -41,14 +41,17 @@ - - - #{msg.USER_LIST_SHARING_ADDRESSBOOKS} + + #{msg.USER_LIST_SHARING_ADDRESSBOOKS} + - - + + + + + diff --git a/web/user/user_profile.xhtml b/web/user/user_profile.xhtml index 4803fbac..fc0f1200 100644 --- a/web/user/user_profile.xhtml +++ b/web/user/user_profile.xhtml @@ -21,13 +21,13 @@ - + Here goes your content. - + - + - +