]> git.mxchange.org Git - addressbook-war.git/commitdiff
As converters and validators cannot fire events, the controller has to load the objec...
authorRoland Haeder <roland@mxchange.org>
Mon, 15 Feb 2016 22:30:36 +0000 (23:30 +0100)
committerRoland Haeder <roland@mxchange.org>
Mon, 15 Feb 2016 22:30:36 +0000 (23:30 +0100)
src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebSessionBean.java
src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebSessionController.java
src/java/org/mxchange/addressbook/beans/profile/UserProfileWebRequestBean.java
src/java/org/mxchange/addressbook/beans/profile/UserProfileWebRequestController.java
web/WEB-INF/templates/generic/user_profile_link.tpl
web/login/login_shared_addressbooks.xhtml
web/login/login_start_sharing_addressbook.xhtml
web/user/show_addressbook.xhtml
web/user/user_list.xhtml

index d01fbbefbb685045276cf80c4d0f541d418c4f27..0d85c24cde6f7fe4e11c375fef83236aa86d1d2a 100644 (file)
@@ -27,7 +27,9 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import javax.annotation.PostConstruct;
 import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Event;
 import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Any;
 import javax.faces.view.facelets.FaceletException;
 import javax.inject.Inject;
 import javax.inject.Named;
@@ -36,7 +38,9 @@ import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import org.mxchange.addressbook.beans.login.UserLoginWebSessionController;
 import org.mxchange.addressbook.events.addressbook.AddressbookLoadedEvent;
+import org.mxchange.addressbook.events.addressbook.LoadedAddressbookEvent;
 import org.mxchange.addressbook.exceptions.AddressbookNameAlreadyUsedException;
+import org.mxchange.addressbook.exceptions.AddressbookNotFoundException;
 import org.mxchange.addressbook.model.addressbook.Addressbook;
 import org.mxchange.addressbook.model.addressbook.AddressbookSessionBeanRemote;
 import org.mxchange.addressbook.model.addressbook.UserAddressbook;
@@ -99,6 +103,13 @@ public class AddressbookWebSessionBean implements AddressbookWebSessionControlle
        @Inject
        private UserLoginWebSessionController loginController;
 
+       /**
+        * Event fired when user has logged in
+        */
+       @Inject
+       @Any
+       private Event<AddressbookLoadedEvent> loadedEvent;
+
        /**
         * A list of all user's address books
         */
@@ -352,6 +363,14 @@ public class AddressbookWebSessionBean implements AddressbookWebSessionControlle
                //this.addressbookBean.getUserCountMap()
        }
 
+       @Override
+       public boolean isAddressbookLoaded () {
+               return ((this.getAddressbookId() instanceof Long)
+                               && (this.getAddressbookName() instanceof String)
+                               && (!this.getAddressbookName().isEmpty())
+                               && (this.getAddressbookUser() instanceof User));
+       }
+
        @Override
        public boolean isAddressbookNameUsed (final String addressbookName) {
                // Is it zero size?
@@ -399,11 +418,35 @@ public class AddressbookWebSessionBean implements AddressbookWebSessionControlle
        }
 
        @Override
-       public boolean isAddressbookLoaded () {
-               return ((this.getAddressbookId() instanceof Long)
-                               && (this.getAddressbookName() instanceof String)
-                               && (!this.getAddressbookName().isEmpty())
-                               && (this.getAddressbookUser() instanceof User));
+       public boolean loadAddressbook () {
+               // Check if the id is set
+               if (this.getAddressbookId() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("this.addressbookId is null");
+               } else if (this.getAddressbookId() < 1) {
+                       // Not valid id
+                       throw new IllegalStateException(MessageFormat.format("this.addressbook={0} is invalid", this.getAddressbookId()));
+               }
+
+               // Default is not found
+               boolean isFound = false;
+
+               try {
+                       // Then try to look it up
+                       Addressbook a = this.addressbookBean.getAddressbookById(this.getAddressbookId());
+
+                       // Fire event here
+                       this.loadedEvent.fire(new LoadedAddressbookEvent(a));
+
+                       // Found it
+                       isFound = true;
+               } catch (final AddressbookNotFoundException ex) {
+                       // Not found!
+                       throw new FaceletException(ex);
+               }
+
+               // Return status
+               return isFound;
        }
 
        /**
index af97a86b2e170bc8f634f0277c100f7dad4f59be..662c0fdbc905c7259443e7ea1684fb9476f22dcf 100644 (file)
@@ -208,4 +208,11 @@ public interface AddressbookWebSessionController extends Serializable {
         * @return Whether the address book is loaded
         */
        boolean isAddressbookLoaded ();
+
+       /**
+        * Loads address book from current id
+        *<p>
+        * @return Whether the address book was found
+        */
+       boolean loadAddressbook ();
 }
index c10dff0c253293bdb433ad6be0a27c7ad8049499..8473c49b4968308fe3ed9d7e3261853a460af430 100644 (file)
@@ -47,11 +47,6 @@ public class UserProfileWebRequestBean implements UserProfileWebRequestControlle
        @Inject
        private UserLoginWebSessionController loginController;
 
-       /**
-        * User instance
-        */
-       private User user;
-
        /**
         * User controller
         */
@@ -59,97 +54,63 @@ public class UserProfileWebRequestBean implements UserProfileWebRequestControlle
        private UserWebSessionController userController;
 
        @Override
-       public User getUser () {
-               return this.user;
-       }
+       public boolean isProfileLinkVisibleById (final Long userId) {
+               // Init user instance
+               User u = null;
 
-       @Override
-       public void setUser (final User user) {
-               this.user = user;
+               try {
+                       // Try to get it
+                       u = userController.lookupUserById(userId);
+               } catch (final UserNotFoundException ex) {
+                       // Throw again
+                       throw new FaceletException(ex);
+               }
+
+               // Is it null?
+               if (null == u) {
+                       // Not found, not visible.
+                       return false;
+               }
+
+               // Ask other method
+               return this.isProfileLinkVisibleByUser(u);
        }
 
        @Override
-       public boolean isProfileLinkVisible () {
+       public boolean isProfileLinkVisibleByUser (final User user) {
                // Check on user
-               if (this.getUser() == null) {
+               if (user == null) {
                        /*
                         * Not set, means wrong invocation of this method as the user
                         * instance needs to be set first.
                         */
-                       throw new NullPointerException("this.user is null"); //NOI18N
-               } else if (this.getUser().getUserId() == null) {
+                       throw new NullPointerException("user is null"); //NOI18N
+               } else if (user.getUserId() == null) {
                        /*
                         * If the id number is not set it means that the user instance has
                         * not been persisted and the JPA has not been flushed. Or a
                         * "virgin" instance (e.g. from registration) has been used.
                         */
-                       throw new NullPointerException("this.user.userId is null"); //NOI18N
-               } else if (this.getUser().getUserId() < 1) {
+                       throw new NullPointerException("user.userId is null"); //NOI18N
+               } else if (user.getUserId() < 1) {
                        /*
                         * The id number is set invalid for an unknown reason.
                         */
-                       throw new IllegalArgumentException(MessageFormat.format("this.user.userId={0} is invalid", this.getUser().getUserId())); //NOI18N
-               } else if (this.getUser().getUserProfileMode() == null) {
+                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
+               } else if (user.getUserProfileMode() == null) {
                        /*
                         * Possibly an out-dated user profile is being used. This should not
                         * happen.
                         */
-                       throw new NullPointerException("this.user.userProfileMode is null"); //NOI18N
+                       throw new NullPointerException("user.userProfileMode is null"); //NOI18N
                }
 
                // Get profile mode from user instance (safe now)
-               ProfileMode profileMode = this.getUser().getUserProfileMode();
+               ProfileMode profileMode = user.getUserProfileMode();
 
                // Check all conditions (except for admin)
                // TODO: Add admin role somehow?
                return ((profileMode.equals(ProfileMode.PUBLIC)) ||
                                 (this.loginController.isUserLoggedIn()) && (profileMode.equals(ProfileMode.MEMBERS)));
        }
-
-       @Override
-       public boolean isProfileLinkVisibleById (final Long userId) {
-               // Init user instance
-               User u = null;
-
-               try {
-                       // Try to get it
-                       u = this.userController.lookupUserById(userId);
-               } catch (final UserNotFoundException ex) {
-                       // Throw again
-                       throw new FaceletException(ex);
-               }
-
-               // Set it here
-               this.setUser(u);
-
-               // Is it null?
-               if (null == u) {
-                       // Not found, not visible.
-                       return false;
-               }
-
-               // Ask other method
-               return this.isProfileLinkVisible();
-       }
-
-       @Override
-       public boolean isProfileLinkVisibleByUser (final User user) {
-               // Is it correctly set?
-               if (null == user) {
-                       // Throw NPE
-                       throw new NullPointerException("user is null");
-               } else if (user.getUserId() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("user.userId is null");
-               } else if (user.getUserId() < 1) {
-                       // Invalid user id set
-                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId()));
-               }
-
-               // Set user here
-               this.setUser(user);
-
-               // Ask other method
-               return this.isProfileLinkVisible();
-       }
 }
index e73068875e51e303353d2410fb926433a2436221..ea9e8c91de1c865c133dcec99886abd9ba93e6f6 100644 (file)
@@ -26,13 +26,6 @@ import org.mxchange.jusercore.model.user.User;
  */
 public interface UserProfileWebRequestController extends Serializable {
 
-       /**
-        * Checks if the current user profile link is visible
-        * <p>
-        * @return Whether the profile link is visible
-        */
-       boolean isProfileLinkVisible ();
-
        /**
         * Checks if the user profile link is visible
         * <p>
@@ -50,18 +43,4 @@ public interface UserProfileWebRequestController extends Serializable {
         * @return Whether the user's profile is visible
         */
        boolean isProfileLinkVisibleByUser (final User user);
-
-       /**
-        * Getter for user instance
-        * <p>
-        * @return User instance
-        */
-       User getUser ();
-
-       /**
-        * Setter for user instance
-        * <p>
-        * @param user User instance
-        */
-       void setUser (final User user);
 }
index c142209e97cdaa673fa06a105fa989af513c7e32..037b83a4a6674bb72ba9350d10a0d17f927c2654 100644 (file)
@@ -5,12 +5,12 @@
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets">
 
-       <h:outputText styleClass="notice" value="#{msg.ERROR_USER_INSTANCE_NOT_SET}" rendered="#{empty profileController.user}" />
+       <h:outputText styleClass="notice" value="#{msg.ERROR_USER_INSTANCE_NOT_SET}" rendered="#{empty user}" />
 
-       <h:outputText class="notice" value="#{msg.USER_PROFILE_NOT_PUBLICLY_VISIBLE}" rendered="#{not empty profileController.user and not profileController.isProfileLinkVisible()}" />
+       <h:outputText class="notice" value="#{msg.USER_PROFILE_NOT_PUBLICLY_VISIBLE}" rendered="#{not empty user and not profileController.isProfileLinkVisibleByUser(user)}" />
 
-       <h:link id="userProfileLink" outcome="user_profile" title="#{msg.LINK_USER_PROFILE_TITLE}" rendered="#{not empty profileController.user and profileController.isProfileLinkVisible()}">
-               <h:outputText id="userName" value="#{profileController.user.userName}" />
-               <f:param name="userId" value="#{profileController.user.userId}" />
+       <h:link id="userProfileLink" outcome="user_profile" title="#{msg.LINK_USER_PROFILE_TITLE}" rendered="#{not empty user and profileController.isProfileLinkVisibleByUser(user)}">
+               <h:outputText id="userName" value="#{user.userName}" />
+               <f:param name="userId" value="#{user.userId}" />
        </h:link>
 </ui:composition>
index e531374fde7a51db9bd333ec0dfec6ea49afd4f3..824c0e88da58c754a8b323bb94a6f646858a304c 100644 (file)
@@ -3,8 +3,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:h="http://xmlns.jcp.org/jsf/html"
-         xmlns:f="http://xmlns.jcp.org/jsf/core"
-         xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
+         xmlns:f="http://xmlns.jcp.org/jsf/core">
 
        <ui:composition template="/WEB-INF/templates/login/login_base.tpl">
                <ui:define name="login_title">#{msg.PAGE_TITLE_LOGIN_SHARED_ADDRESSBOOKS}</ui:define>
@@ -21,8 +20,6 @@
 
                                <div class="para">
                                        <h:dataTable id="sharedAddressbooks" var="share" value="#{shareController.allShares()}" headerClass="table_data_column" summary="#{msg.TABLE_SUMMARY_LOGIN_SHARED_ADDRESSBOOKS}" rendered="#{shareController.isSharingAddressbooks()}">
-                                               <c:set value="#{share.shareUserSharee}" target="#{profileController}" property="user" />
-
                                                <h:column>
                                                        <f:facet name="header">#{msg.SHARED_ADDRESSBOOK}</f:facet>
 
@@ -34,7 +31,9 @@
 
                                                <h:column>
                                                        <f:facet name="header">#{msg.SHAREE_USER_NAME}</f:facet>
-                                                       <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl" />
+                                                       <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl">
+                                                               <ui:param name="user" value="#{share.setShareUserSharee(shareUserSharer)}" />
+                                                       </ui:include>
                                                </h:column>
 
                                                <h:column>
index f86110d8833c5b990145c8f697b36ee45e199d69..491ad98cbf0fe1fa04e1c58ff401dc989042de94 100644 (file)
@@ -32,7 +32,9 @@
 
                                                <h:column>
                                                        <f:facet name="header">#{msg.USER_NAME}</f:facet>
-                                                       <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl" />
+                                                       <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl">
+                                                               <ui:param name="user" value="#{user}" />
+                                                       </ui:include>
                                                </h:column>
 
                                                <h:column>
index 7000aaedff5e97ac73edd7b280876525496c3acf..e7137614ba71304e4ab3099c8bac31099a9c88b9 100644 (file)
@@ -3,8 +3,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:h="http://xmlns.jcp.org/jsf/html"
-         xmlns:f="http://xmlns.jcp.org/jsf/core"
-         xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
+         xmlns:f="http://xmlns.jcp.org/jsf/core">
 
        <f:metadata>
                <f:viewParam id="addressbookId" name="addressbookId" value="#{addressbookController.addressbookId}" required="true" requiredMessage="#{msg.PARAMETER_ADDRESSBOOK_ID_MISSING}" converterMessage="#{msg.PARAMETER_ADDRESSBOOK_ID_INVALID}" validatorMessage="#{msg.PARAMETER_ADDRESSBOOK_ID_NOT_FOUND}">
@@ -22,9 +21,7 @@
                </ui:define>
 
                <ui:define name="content">
-                       <h:panelGrid headerClass="table_header" styleClass="table" columns="2" rendered="#{addressbookController.isAddressbookLoaded()}">
-                               <c:set value="#{addressbookController.addressbookUser}" target="#{profileController}" property="user" />
-
+                       <h:panelGrid headerClass="table_header" styleClass="table" columns="2" rendered="#{addressbookController.loadAddressbook()}">
                                <f:facet name="header">#{msg.TABLE_HEADER_SHOW_ADDRESSBOOK}</f:facet>
 
                                <h:outputLabel for="addressbookId" class="table_label">#{msg.ADDRESSBOOK_ID}</h:outputLabel>
@@ -34,7 +31,9 @@
                                <h:outputText id="addressbookName" value="#{addressbookController.addressbookName}" />
 
                                <h:outputLabel for="userProfileLink" class="table_label">#{msg.ADDRESSBOOK_OWNER}</h:outputLabel>
-                               <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl" />
+                               <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl">
+                                       <ui:param name="user" value="#{addressbookController.addressbookUser}" />
+                               </ui:include>
 
                                <h:outputLabel for="addressbookCreated" class="table_label">#{msg.ADDRESSBOOK_CREATED}</h:outputLabel>
                                <h:outputFormat id="addressbookCreated" value="#{addressbookController.addressbook.addressbookCreated.time}" title="#{msg.ADDRESSBOOK_CREATED_TITLE}">
index 12f18f92afcecc8eee3656f0a08bd266dd9f6bef..8f5f4b63ab270ee1031d4cad511978e004a96192 100644 (file)
@@ -3,8 +3,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:h="http://xmlns.jcp.org/jsf/html"
-         xmlns:f="http://xmlns.jcp.org/jsf/core"
-         xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
+         xmlns:f="http://xmlns.jcp.org/jsf/core">
 
        <ui:composition template="/WEB-INF/templates/#{loginController.templateType}/#{loginController.templateType}_base.tpl">
                <ui:define name="login_title">#{msg.PAGE_TITLE_USER_LIST}</ui:define>
                                </div>
 
                                <h:dataTable id="userList" var="user" value="#{userController.allVisibleUsers()}" headerClass="table_header_column25" summary="#{msg.TABLE_SUMMARY_USER_LIST}" rendered="#{userController.isVisibleUserFound()}">
-                                       <c:set value="#{share.shareUserSharee}" target="#{profileController}" property="user" />
                                        <h:column>
                                                <f:facet name="header">#{msg.USER_ID}</f:facet>
-                                               <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl" />
+                                               <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl">
+                                                       <ui:param name="user" value="#{user}" />
+                                               </ui:include>
                                        </h:column>
 
                                        <h:column>
                                                <f:facet name="header">#{msg.USER_NAME}</f:facet>
-                                               <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl" />
+                                               <ui:include src="/WEB-INF/templates/generic/user_profile_link.tpl">
+                                                       <ui:param name="user" value="#{user}" />
+                                               </ui:include>
                                        </h:column>
 
                                        <h:column>