From 3d860a341bd880ec23caf763001dc71247826b6b Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 9 Oct 2015 14:50:23 +0200 Subject: [PATCH] =?utf8?q?Continued:=20-=20added=20bean=20method=20isLogge?= =?utf8?q?dIn()=20to=20check=20if=20the=20user=20is=20logged-in=20(current?= =?utf8?q?ly=20on=20if=20the=20instance=20is=20set)=20-=20added=20@PostCon?= =?utf8?q?struct=20method=20init()=20to=20initialize=20addressbook=20list?= =?utf8?q?=20for=20current=20user=20(or=20empty=20list=20if=20not=20logged?= =?utf8?q?=20in)=20-=20implemented=20hasCreatedAddressbooks()=20Signed-off?= =?utf8?q?-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- nbproject/faces-config.NavData | 56 +++++++++---------- .../beans/addressbook/AddressbookWebBean.java | 23 +++++++- .../beans/login/UserLoginWebBean.java | 6 ++ .../beans/login/UserLoginWebController.java | 7 +++ 4 files changed, 63 insertions(+), 29 deletions(-) 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 (); } -- 2.39.5