]> git.mxchange.org Git - jfinancials-war.git/commitdiff
Continued:
authorRoland Haeder <roland@mxchange.org>
Thu, 15 Oct 2015 15:40:49 +0000 (17:40 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 15 Oct 2015 15:40:49 +0000 (17:40 +0200)
- 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

src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java
src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebController.java
src/java/org/mxchange/addressbook/beans/login/UserLoginWebBean.java
src/java/org/mxchange/addressbook/beans/login/UserLoginWebController.java
web/WEB-INF/templates/login/login_base.tpl
web/login/login_list_sharing_addressbooks.xhtml
web/login/login_show_addressbook.xhtml
web/user/user_list.xhtml
web/user/user_profile.xhtml

index d9c19638433cfe0bde7310412f8eb928c8632fbb..e69455e72deacfabff406ef38612da7c05fbdbe0 100644 (file)
@@ -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)
  * <p>
  * @author Roland Haeder<roland@mxchange.org>
  */
@@ -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<Addressbook> 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());
-       }
 }
index 463e1a0771bb9be94beaba03e2715d622ff28e7e..f1cf0c450cbe9290070a227b56a079e2bcadc7d7 100644 (file)
@@ -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
  * <p>
  * @author Roland Haeder<roland@mxchange.org>
  */
@@ -152,5 +152,14 @@ public interface AddressbookWebController extends Serializable {
         * <p>
         * @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
+        * <p>
+        * @param user User instance to look for
+        * <p>
+        * @return Count of user's shared address books
+        */
+       Integer countAllUserSharedAddressbooks (final User user);
 }
index ffdf341bfe33b52c4632ee541bd98033420429a4..c90b8b7fdf6ddab00f315fd9ce5c83024bf8fffa 100644 (file)
@@ -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;
        }
 }
index 4482179bb9548ea08fd4d6651ea70bc563728e19..507c8dbd69d83bb517f67797f4257bd681cdcc3f 100644 (file)
@@ -67,4 +67,11 @@ public interface UserLoginWebController extends Serializable {
         * @return Whether the user is logged-in
         */
        boolean isUserLoggedIn ();
+
+       /**
+        * Is this truly a guest?
+        * <p>
+        * @return Whether the user is truly a guest
+        */
+       boolean isGuest ();
 }
index b8139383b2e491ac29fe80f23f399ff9839cfa4e..abd205b7778faaf725475f1a6fe4b3c29c1d6fd0 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <ui:composition
-       rendered="#{loginController.userLoggedIn}"
+       rendered="#{loginController.isUserLoggedIn()}"
        template="/WEB-INF/templates/base.tpl"
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:ui="http://java.sun.com/jsf/facelets">
index d2064dd426fc98a65020f3076e79e085c3a93a34..471a1f18374c6b081bd5bc5fe8c07a9666359966 100644 (file)
                </ui:define>
 
                <ui:define name="content">
-                       <h:outputText rendered="#{shareController.isShareeUserIdSet()}">
+                       <ui:fragment rendered="#{shareController.isShareeUserIdSet()}">
                                Here goes your content.
-                       </h:outputText>
+                       </ui:fragment>
 
-                       <h:outputText rendered="#{shareController.isShareeUserIdEmpty()}">
+                       <ui:fragment rendered="#{shareController.isShareeUserIdEmpty()}">
                                <ui:include src="/WEB-INF/templates/generic/userid_error.tpl" />
-                       </h:outputText>
+                       </ui:fragment>
                </ui:define>
        </ui:composition>
 </html>
index 27c9e27da63034447339675248c8aa6d0c1da706..63cbdbde66fad31dbd45fa9d79803fbfe7ca7203 100644 (file)
                                </div>
 
                                <div class="table_footer">
-                                       <h:outputText rendered="#{addressbookController.isOwnAddressbook()}">
+                                       <ui:fragment rendered="#{addressbookController.isOwnAddressbook()}">
                                                <h:link id="startSharing" outcome="login_start_sharing_addressbook" value="#{msg.LINK_LOGIN_START_SHARING_ADDRESSBOOK}" title="#{msg.LINK_LOGIN_START_SHARING_ADDRESSBOOK_TITLE}" />
-                                       </h:outputText>
-                                       <h:outputText rendered="#{addressbookController.isOtherAddressbook()}">
+                                       </ui:fragment>
+
+                                       <ui:fragment rendered="#{addressbookController.isOtherAddressbook()}">
                                                Bla bla
-                                       </h:outputText>
+                                       </ui:fragment>
                                </div>
                        </div>
                </ui:define>
index 9ccd87328e4573c26a1b2ab622dcf7d73d732644..a10bcb503c4edd5a020d1d514c5882dedb121ff0 100644 (file)
                                                </h:outputFormat>
                                        </h:column>
 
-                                       <h:outputText rendered="#{loginController.userLoggedIn}">
-                                               <h:column>
-                                                       <f:facet name="header">#{msg.USER_LIST_SHARING_ADDRESSBOOKS}</f:facet>
+                                       <h:column>
+                                               <f:facet name="header">#{msg.USER_LIST_SHARING_ADDRESSBOOKS}</f:facet>
+                                               <ui:fragment rendered="#{loginController.isUserLoggedIn()}">
                                                        <h:link outcome="login_list_sharing_addressbooks" value="#{msg.LINK_LOGIN_LIST_SHARING_ADDRESSBOOKS}" title="#{msg.LINK_LOGIN_LIST_SHARING_ADDRESSBOOKS_TITLE}">
                                                                <f:param name="userId" value="#{user.userId}" />
                                                        </h:link>
-                                               </h:column>
-                                       </h:outputText>
+                                               </ui:fragment>
+                                               <ui:fragment rendered="#{loginController.isGuest()}">
+                                                       <h:outputText id="userShared" value="#{addressbookController.countAllUserSharedAddressbooks(user)}" />
+                                               </ui:fragment>
+                                       </h:column>
                                </h:dataTable>
                        </div>
                </ui:define>
index 4803fbac1c045e9394211eb489411999e5023c66..fc0f120007aca8d3ee3a8bded2b3dc8e92d0c044 100644 (file)
                </ui:define>
 
                <ui:define name="content">
-                       <h:outputText rendered="#{shareController.isShareeUserIdSet()}">
+                       <ui:fragment rendered="#{shareController.isShareeUserIdSet()}">
                                Here goes your content.
-                       </h:outputText>
+                       </ui:fragment>
 
-                       <h:outputText rendered="#{shareController.isShareeUserIdEmpty()}">
+                       <ui:fragment rendered="#{shareController.isShareeUserIdEmpty()}">
                                <ui:include src="/WEB-INF/templates/generic/userid_error.tpl" />
-                       </h:outputText>
+                       </ui:fragment>
                </ui:define>
        </ui:composition>
 </html>