From: Roland Haeder Date: Mon, 15 Feb 2016 22:30:23 +0000 (+0100) Subject: As converters and validators cannot fire events, the controller has to load the objec... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=bdc721420fe782f5d6eb3d71bcf1ffba0a4c455b;p=jjobs-war.git As converters and validators cannot fire events, the controller has to load the object and fire the event. --- diff --git a/lib/addressbook-lib.jar b/lib/addressbook-lib.jar index a63b5630..7b370e14 100644 Binary files a/lib/addressbook-lib.jar and b/lib/addressbook-lib.jar differ diff --git a/src/java/org/mxchange/jjobs/beans/addressbook/AddressbookWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/addressbook/AddressbookWebSessionBean.java index b17bc22f..6ef381b6 100644 --- a/src/java/org/mxchange/jjobs/beans/addressbook/AddressbookWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/addressbook/AddressbookWebSessionBean.java @@ -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 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 */ diff --git a/src/java/org/mxchange/jjobs/beans/addressbook/AddressbookWebSessionController.java b/src/java/org/mxchange/jjobs/beans/addressbook/AddressbookWebSessionController.java index 303d4f7b..02ea4043 100644 --- a/src/java/org/mxchange/jjobs/beans/addressbook/AddressbookWebSessionController.java +++ b/src/java/org/mxchange/jjobs/beans/addressbook/AddressbookWebSessionController.java @@ -208,4 +208,11 @@ public interface AddressbookWebSessionController extends Serializable { * @return Whether the address book is loaded */ boolean isAddressbookLoaded (); + + /** + * Loads address book from current id + *

+ * @return Whether the address book was found + */ + boolean loadAddressbook (); } diff --git a/web/user/show_addressbook.xhtml b/web/user/show_addressbook.xhtml index 686605a0..e7137614 100644 --- a/web/user/show_addressbook.xhtml +++ b/web/user/show_addressbook.xhtml @@ -21,7 +21,7 @@ - + #{msg.TABLE_HEADER_SHOW_ADDRESSBOOK} #{msg.ADDRESSBOOK_ID}