]> git.mxchange.org Git - addressbook-war.git/commitdiff
init() and @PostConstruct is the wrong place for checking logged-in user status,...
authorRoland Haeder <roland@mxchange.org>
Mon, 15 Feb 2016 19:26:37 +0000 (20:26 +0100)
committerRoland Haeder <roland@mxchange.org>
Mon, 15 Feb 2016 19:26:37 +0000 (20:26 +0100)
src/java/org/mxchange/addressbook/beans/shares/SharesWebSessionBean.java
src/java/org/mxchange/addressbook/beans/shares/SharesWebSessionController.java

index 307605808c50db772dddba3b6d82f01fa8b6b9e7..433a744656bd0468d9bffd0e16a2e8ee5ab1002f 100644 (file)
@@ -39,6 +39,7 @@ import org.mxchange.addressbook.exceptions.UserAlreadySharingAddressbookExceptio
 import org.mxchange.addressbook.model.addressbook.Addressbook;
 import org.mxchange.addressbook.model.addressbook.shared.ShareableAddressbook;
 import org.mxchange.addressbook.model.shared.SharedAddressbooksSessionBeanRemote;
+import org.mxchange.jusercore.events.login.UserLoggedInEvent;
 import org.mxchange.jusercore.model.user.User;
 import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
 
@@ -184,16 +185,23 @@ public class SharesWebSessionBean implements SharesWebSessionController {
                this.shareeUserId = shareeUserId;
        }
 
-       @PostConstruct
-       public void init () {
-               // Check conditions
-               if (!this.loginController.isUserLoggedIn()) {
-                       // No, then throw exception
-                       throw new FaceletException("This method can only be called as logged-in user."); //NOI18N
+       @Override
+       public void afterLoginEvent (final @Observes UserLoggedInEvent event) {
+               // Is the user logged in?
+               if (null == event) {
+                       // Is null
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getUser() == null) {
+                       // user is null
+                       throw new NullPointerException("event.user is null"); //NOI18N
                }
 
                // Init share list
-               this.sharedAddressbooks = this.shareBean.allSharedAddressbooks(this.loginController.getLoggedInUser());
+               this.sharedAddressbooks = this.shareBean.allSharedAddressbooks(event.getUser());
+       }
+
+       @PostConstruct
+       public void init () {
        }
 
        @Override
index 1be32834e296ca18a2b9e9fa073f3bbdb4c34038..0e9eacdb4e9a1447881be6b2b0e78e79254e1cbd 100644 (file)
@@ -21,6 +21,7 @@ import java.util.List;
 import org.mxchange.addressbook.events.sharing.AddressbookSharingEvent;
 import org.mxchange.addressbook.model.addressbook.Addressbook;
 import org.mxchange.addressbook.model.addressbook.shared.ShareableAddressbook;
+import org.mxchange.jusercore.events.login.UserLoggedInEvent;
 import org.mxchange.jusercore.model.user.User;
 
 /**
@@ -109,4 +110,12 @@ public interface SharesWebSessionController extends Serializable {
         * @return Redirect target
         */
        String startSharing (final User user, final Addressbook addressbook);
+
+       /**
+        * This method is called when a user has successfully logged in his/her
+        * account.
+        * <p>
+        * @param event
+        */
+       void afterLoginEvent (final UserLoggedInEvent event);
 }