]> git.mxchange.org Git - jjobs-war.git/commitdiff
As converters and validators cannot fire events, the controller has to load the objec...
authorRoland Haeder <roland@mxchange.org>
Mon, 15 Feb 2016 22:30:23 +0000 (23:30 +0100)
committerRoland Haeder <roland@mxchange.org>
Mon, 15 Feb 2016 22:30:23 +0000 (23:30 +0100)
lib/addressbook-lib.jar
src/java/org/mxchange/jjobs/beans/addressbook/AddressbookWebSessionBean.java
src/java/org/mxchange/jjobs/beans/addressbook/AddressbookWebSessionController.java
web/user/show_addressbook.xhtml

index a63b563001b349091d70b01c7528dc0d637ad2e2..7b370e141bfff02a485da19f3e926d93d8a73675 100644 (file)
Binary files a/lib/addressbook-lib.jar and b/lib/addressbook-lib.jar differ
index b17bc22f1d7ef580bb03b9616b90dc6b995203c4..6ef381b6db94605966b28fc930507019aa5945a6 100644 (file)
@@ -27,7 +27,9 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import javax.annotation.PostConstruct;
 import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Event;
 import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Any;
 import javax.faces.view.facelets.FaceletException;
 import javax.inject.Inject;
 import javax.inject.Named;
@@ -35,7 +37,9 @@ import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import org.mxchange.addressbook.events.addressbook.AddressbookLoadedEvent;
+import org.mxchange.addressbook.events.addressbook.LoadedAddressbookEvent;
 import org.mxchange.addressbook.exceptions.AddressbookNameAlreadyUsedException;
+import org.mxchange.addressbook.exceptions.AddressbookNotFoundException;
 import org.mxchange.addressbook.model.addressbook.Addressbook;
 import org.mxchange.addressbook.model.addressbook.AddressbookSessionBeanRemote;
 import org.mxchange.addressbook.model.addressbook.UserAddressbook;
@@ -99,6 +103,13 @@ public class AddressbookWebSessionBean implements AddressbookWebSessionControlle
        @Inject
        private UserLoginWebSessionController loginController;
 
+       /**
+        * Event fired when user has logged in
+        */
+       @Inject
+       @Any
+       private Event<AddressbookLoadedEvent> loadedEvent;
+
        /**
         * A list of all user's address books
         */
@@ -406,6 +417,38 @@ public class AddressbookWebSessionBean implements AddressbookWebSessionControlle
                return Objects.equals(this.getAddressbookUser(), this.loginController.getLoggedInUser());
        }
 
+       @Override
+       public boolean loadAddressbook () {
+               // Check if the id is set
+               if (this.getAddressbookId() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("this.addressbookId is null");
+               } else if (this.getAddressbookId() < 1) {
+                       // Not valid id
+                       throw new IllegalStateException(MessageFormat.format("this.addressbook={0} is invalid", this.getAddressbookId()));
+               }
+
+               // Default is not found
+               boolean isFound = false;
+
+               try {
+                       // Then try to look it up
+                       Addressbook a = this.addressbookBean.getAddressbookById(this.getAddressbookId());
+
+                       // Fire event here
+                       this.loadedEvent.fire(new LoadedAddressbookEvent(a));
+
+                       // Found it
+                       isFound = true;
+               } catch (final AddressbookNotFoundException ex) {
+                       // Not found!
+                       throw new FaceletException(ex);
+               }
+
+               // Return status
+               return isFound;
+       }
+
        /**
         * Initializes the user user's address book list
         */
index 303d4f7b38fa5a816b314d4607d5d5b1fa4b8363..02ea4043a5d6fb804aa496b80da027631711e573 100644 (file)
@@ -208,4 +208,11 @@ public interface AddressbookWebSessionController extends Serializable {
         * @return Whether the address book is loaded
         */
        boolean isAddressbookLoaded ();
+
+       /**
+        * Loads address book from current id
+        *<p>
+        * @return Whether the address book was found
+        */
+       boolean loadAddressbook ();
 }
index 686605a068b6ba3d31579793315ea95c8c906021..e7137614ba71304e4ab3099c8bac31099a9c88b9 100644 (file)
@@ -21,7 +21,7 @@
                </ui:define>
 
                <ui:define name="content">
-                       <h:panelGrid headerClass="table_header" styleClass="table" columns="2" rendered="#{addressbookController.isAddressbookLoaded()}">
+                       <h:panelGrid headerClass="table_header" styleClass="table" columns="2" rendered="#{addressbookController.loadAddressbook()}">
                                <f:facet name="header">#{msg.TABLE_HEADER_SHOW_ADDRESSBOOK}</f:facet>
 
                                <h:outputLabel for="addressbookId" class="table_label">#{msg.ADDRESSBOOK_ID}</h:outputLabel>