]> git.mxchange.org Git - addressbook-war.git/commitdiff
Continued:
authorRoland Haeder <roland@mxchange.org>
Fri, 9 Oct 2015 12:50:23 +0000 (14:50 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 9 Oct 2015 13:26:54 +0000 (15:26 +0200)
- 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 <roland@mxchange.org>

nbproject/faces-config.NavData
src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java
src/java/org/mxchange/addressbook/beans/login/UserLoginWebBean.java
src/java/org/mxchange/addressbook/beans/login/UserLoginWebController.java

index b4a27a42a929a1fc0620adc7b534d39c5d05fe69..f1818296af74640d985e4899bb0929b4b2a1c44a 100644 (file)
@@ -1,55 +1,55 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scene Scope="Project" version="2">
     <Scope Scope="Faces Configuration Only">
+        <Node id="admin/admin_logout.xhtml" x="650" y="150" zoom="true"/>
+        <Node id="user/login.xhtml" x="150" y="300" zoom="true"/>
+        <Node id="admin/index.xhtml" x="400" y="300" zoom="true"/>
+        <Node id="user/lost_passwd.xhtml" x="400" y="450" zoom="true"/>
+        <Node id="*" x="1150" y="150" zoom="true"/>
+        <Node id="terms.xhtml" x="400" y="150" zoom="true"/>
         <Node id="bye.xhtml" x="150" y="450" zoom="true"/>
-        <Node id="index.xhtml" x="900" y="150" zoom="true"/>
         <Node id="privacy.xhtml" x="650" y="300" zoom="true"/>
-        <Node id="*" x="1150" y="150" zoom="true"/>
+        <Node id="index.xhtml" x="900" y="150" zoom="true"/>
         <Node id="imprint.xhtml" x="150" y="600" zoom="true"/>
         <Node id="admin/category.xhtml" x="650" y="450" zoom="true"/>
-        <Node id="admin/index.xhtml" x="400" y="300" zoom="true"/>
         <Node id="user/register.xhtml" x="150" y="150" zoom="true"/>
-        <Node id="admin/admin_logout.xhtml" x="650" y="150" zoom="true"/>
-        <Node id="terms.xhtml" x="400" y="150" zoom="true"/>
         <Node id="admin/product.xhtml" x="900" y="300" zoom="true"/>
-        <Node id="user/lost_passwd.xhtml" x="400" y="450" zoom="true"/>
-        <Node id="user/login.xhtml" x="150" y="300" zoom="true"/>
     </Scope>
     <Scope Scope="Project">
-        <Node id="bye.xhtml" x="650" y="300" zoom="true"/>
-        <Node id="index.xhtml" x="650" y="600" zoom="true"/>
-        <Node id="user/register_done.xhtml" x="1150" y="300" zoom="true"/>
+        <Node id="admin/admin_logout.xhtml" x="400" y="600" zoom="true"/>
+        <Node id="user/login.xhtml" x="900" y="150" zoom="true"/>
         <Node id="login/login_edit_address.xhtml" x="150" y="300" zoom="true"/>
-        <Node id="privacy.xhtml" x="400" y="750" zoom="true"/>
+        <Node id="login/login_edit_user_data.xhtml" x="1150" y="150" zoom="true"/>
+        <Node id="login/login_other_addressbooks.xhtml" x="650" y="450" zoom="true"/>
+        <Node id="user/lost_passwd.xhtml" x="900" y="300" zoom="true"/>
         <Node id="*" x="650" y="150" zoom="true"/>
-        <Node id="imprint.xhtml" x="900" y="450" zoom="true"/>
+        <Node id="terms.xhtml" x="150" y="600" zoom="true"/>
+        <Node id="login/login_own_addressbooks.xhtml" x="400" y="150" zoom="true"/>
+        <Node id="user/register_done.xhtml" x="1150" y="300" zoom="true"/>
+        <Node id="bye.xhtml" x="650" y="300" zoom="true"/>
         <Node id="user/login_error.xhtml" x="1400" y="150" zoom="true"/>
+        <Node id="privacy.xhtml" x="400" y="750" zoom="true"/>
+        <Node id="admin/admin_index.xhtml" x="400" y="450" zoom="true"/>
+        <Node id="index.xhtml" x="650" y="600" zoom="true"/>
         <Node id="login/login_user_list.xhtml" x="150" y="150" zoom="true"/>
+        <Node id="imprint.xhtml" x="900" y="450" zoom="true"/>
+        <Node id="login/login_index.xhtml" x="150" y="750" zoom="true"/>
         <Node id="user/register.xhtml" x="400" y="300" zoom="true"/>
-        <Node id="login/login_other_addressbooks.xhtml" x="650" y="450" zoom="true"/>
         <Node id="user/resend_link.xhtml" x="150" y="450" zoom="true"/>
-        <Node id="login/login_index.xhtml" x="150" y="750" zoom="true"/>
-        <Node id="login/login_own_addressbooks.xhtml" x="400" y="150" zoom="true"/>
-        <Node id="admin/admin_index.xhtml" x="400" y="450" zoom="true"/>
-        <Node id="terms.xhtml" x="150" y="600" zoom="true"/>
-        <Node id="admin/admin_logout.xhtml" x="400" y="600" zoom="true"/>
-        <Node id="user/lost_passwd.xhtml" x="900" y="300" zoom="true"/>
-        <Node id="user/login.xhtml" x="900" y="150" zoom="true"/>
-        <Node id="login/login_edit_user_data.xhtml" x="1150" y="150" zoom="true"/>
     </Scope>
     <Scope Scope="All Faces Configurations">
+        <Node id="admin/admin_logout.xhtml" x="650" y="150" zoom="true"/>
+        <Node id="user/login.xhtml" x="150" y="300" zoom="true"/>
+        <Node id="admin/index.xhtml" x="400" y="300" zoom="true"/>
+        <Node id="user/lost_passwd.xhtml" x="400" y="450" zoom="true"/>
+        <Node id="*" x="1150" y="150" zoom="true"/>
+        <Node id="terms.xhtml" x="400" y="150" zoom="true"/>
         <Node id="bye.xhtml" x="150" y="450" zoom="true"/>
-        <Node id="index.xhtml" x="900" y="150" zoom="true"/>
         <Node id="privacy.xhtml" x="650" y="300" zoom="true"/>
-        <Node id="*" x="1150" y="150" zoom="true"/>
+        <Node id="index.xhtml" x="900" y="150" zoom="true"/>
         <Node id="imprint.xhtml" x="150" y="600" zoom="true"/>
         <Node id="admin/category.xhtml" x="650" y="450" zoom="true"/>
-        <Node id="admin/index.xhtml" x="400" y="300" zoom="true"/>
         <Node id="user/register.xhtml" x="150" y="150" zoom="true"/>
-        <Node id="admin/admin_logout.xhtml" x="650" y="150" zoom="true"/>
-        <Node id="terms.xhtml" x="400" y="150" zoom="true"/>
         <Node id="admin/product.xhtml" x="900" y="300" zoom="true"/>
-        <Node id="user/lost_passwd.xhtml" x="400" y="450" zoom="true"/>
-        <Node id="user/login.xhtml" x="150" y="300" zoom="true"/>
     </Scope>
 </Scene>
index f1b563e4f6a22abf47ba5b77d3867a63a9569df3..7bd707f9a3b3ed64285213fe5ae7657a3f00a9ac 100644 (file)
@@ -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());
        }
 }
index afacfbf93da17df600aa437021fc54e4dde6fc11..feff2584004e62bcd4379aea9e1bfc6fbb07b479 100644 (file)
@@ -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);
+       }
 }
index 1e807a64cd73d988e779633e4947772a655e6d69..89e5184653b8c8213f2b46c449efccb2a4bbdc97 100644 (file)
@@ -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
+        * <p>
+        * @return Whether the user is logged-in
+        */
+       public boolean isLoggedIn ();
 }