From: Roland Haeder Date: Mon, 15 Feb 2016 19:26:37 +0000 (+0100) Subject: init() and @PostConstruct is the wrong place for checking logged-in user status,... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a506685da045b9dd9693e85a918b96dbb2c9e18d;p=jfinancials-war.git init() and @PostConstruct is the wrong place for checking logged-in user status, better use the new event --- diff --git a/src/java/org/mxchange/addressbook/beans/shares/SharesWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/shares/SharesWebSessionBean.java index 30760580..433a7446 100644 --- a/src/java/org/mxchange/addressbook/beans/shares/SharesWebSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/shares/SharesWebSessionBean.java @@ -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 diff --git a/src/java/org/mxchange/addressbook/beans/shares/SharesWebSessionController.java b/src/java/org/mxchange/addressbook/beans/shares/SharesWebSessionController.java index 1be32834..0e9eacdb 100644 --- a/src/java/org/mxchange/addressbook/beans/shares/SharesWebSessionController.java +++ b/src/java/org/mxchange/addressbook/beans/shares/SharesWebSessionController.java @@ -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. + *

+ * @param event + */ + void afterLoginEvent (final UserLoggedInEvent event); }