From: Roland Haeder Date: Fri, 9 Oct 2015 12:50:23 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3d860a341bd880ec23caf763001dc71247826b6b;p=addressbook-war.git Continued: - added bean method isLoggedIn() to check if the user is logged-in (currently on if the instance is set) - added @PostConstruct method init() to initialize addressbook list for current user (or empty list if not logged in) - implemented hasCreatedAddressbooks() Signed-off-by:Roland Häder --- diff --git a/nbproject/faces-config.NavData b/nbproject/faces-config.NavData index b4a27a42..f1818296 100644 --- a/nbproject/faces-config.NavData +++ b/nbproject/faces-config.NavData @@ -1,55 +1,55 @@ + + + + + + - - + - - - - - - - - + + - + + + - + + + + + + + + + - - - - - - - - - + + + + + + - - + - - - - - diff --git a/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java b/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java index f1b563e4..7bd707f9 100644 --- a/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java +++ b/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java @@ -16,7 +16,9 @@ */ package org.mxchange.addressbook.beans.addressbook; +import java.util.ArrayList; import java.util.List; +import javax.annotation.PostConstruct; import javax.enterprise.context.SessionScoped; import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; @@ -76,8 +78,27 @@ public class AddressbookWebBean implements AddressbookWebController { } } + @PostConstruct + public void init () { + // Init list + this.addressbookList = new ArrayList<>(0); + + // Is the user logged-in? + if (this.loginController.isLoggedIn()) { + // Fill list with entries + this.addressbookList = this.addressbookBean.getUsersList(this.loginController.getLoggedInUser()); + } + } + @Override public boolean hasCreatedAddressbooks () { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + // Is the user logged in? + if (!this.loginController.isLoggedIn()) { + // Not logged in + throw new FaceletException("This method can only be called as logged-in user."); + } + + // Check if the list is filled + return (!this.addressbookList.isEmpty()); } } diff --git a/src/java/org/mxchange/addressbook/beans/login/UserLoginWebBean.java b/src/java/org/mxchange/addressbook/beans/login/UserLoginWebBean.java index afacfbf9..feff2584 100644 --- a/src/java/org/mxchange/addressbook/beans/login/UserLoginWebBean.java +++ b/src/java/org/mxchange/addressbook/beans/login/UserLoginWebBean.java @@ -105,4 +105,10 @@ public class UserLoginWebBean implements UserLoginWebController { public void setLoggedInUser (final User loggedInUser) { this.loggedInUser = loggedInUser; } + + @Override + public boolean isLoggedIn () { + // Compare instance + return (this.getLoggedInUser() instanceof User); + } } diff --git a/src/java/org/mxchange/addressbook/beans/login/UserLoginWebController.java b/src/java/org/mxchange/addressbook/beans/login/UserLoginWebController.java index 1e807a64..89e51846 100644 --- a/src/java/org/mxchange/addressbook/beans/login/UserLoginWebController.java +++ b/src/java/org/mxchange/addressbook/beans/login/UserLoginWebController.java @@ -46,4 +46,11 @@ public interface UserLoginWebController extends Serializable { * @param loggedInUser Logged-in user instance */ public void setLoggedInUser (final User loggedInUser); + + /** + * Checks whether the user is logged-in + *

+ * @return Whether the user is logged-in + */ + public boolean isLoggedIn (); }