From bdc721420fe782f5d6eb3d71bcf1ffba0a4c455b Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Mon, 15 Feb 2016 23:30:23 +0100 Subject: [PATCH] As converters and validators cannot fire events, the controller has to load the object and fire the event. --- lib/addressbook-lib.jar | Bin 52636 -> 53358 bytes .../AddressbookWebSessionBean.java | 43 ++++++++++++++++++ .../AddressbookWebSessionController.java | 7 +++ web/user/show_addressbook.xhtml | 2 +- 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/lib/addressbook-lib.jar b/lib/addressbook-lib.jar index a63b563001b349091d70b01c7528dc0d637ad2e2..7b370e141bfff02a485da19f3e926d93d8a73675 100644 GIT binary patch delta 2265 zcmY+Fd2mzJ7stQvy){S5zQrxbE#K^ zl5)SAd z@4@dUFu&b-TE-vl++$&R%6(RC+{yUzCBGCkf0&aD@KYhqXhkCFyi<6dPKbyEOvbHN z+@@o#4ePKz5t+DM#~oIb+AswH9X0Gyn+O9z9d$bHw4&aItI%MB9gVEtpkt#IAsZZM z(6Pyi&1?!=@gGjnq@&q}iDNNx*+8iRq> zIrhH{K=UE{NpWlogqt}Ux&nK-6^Qye{p>RzgRB*)v?z#;%SIXJp z=6cVjt+frbuR6~aj-E~7U|nd8MpOGsHEI%&W}=R6hDpdgPV75Vf~(d0WF0OJ$`V2KihMD94e&Hv;xac}a_H4w zE#EcWovxW;u(~6INbs5|(w1)SMxu&?FnVG4_u?wQBZ*=tSGt*##E=|A%D_La<5YMp z>6Rg+_rl?Kq>gnRKX43_y!yYH(#D#T)Abl8aIT2rxJEATH0>=&A3ztbrfSTj{dkc? z<2?Fbl~7d{(|*fvBbL(WBhOW6!Wy*UR*JcuqShjc^>_g_=tV7VpvbjUmnMpyh1pcO zD6%Np3!N*4IhaeNw+M=93PmdCV*!4^&-db$aTdqX@ED!Nd=daO%c%-f%=mAvp&St?(&(_Z~XUhrx0 z8&vKl%X)64o+kG8$YylDM|O-qNl6`Jc5f*o((7aVFyItl^~w%6wQnVBI{N&K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3V`Ae1WoX3e zSuu8FJKjYpn)%FI=wt`TIOTIY^t ztUxkkdR;A2kP02WzuiQMH>iJlepeggFP9ce(%nuG+P{qM15wcwImGzcYcxUJ?obz8N3#`bx<*yqK`u_~4u$Ia5@2jb_EcoBRmMEpAL#ol+w z>o_S6%JamIQN5`6I6$;_=*7Kp6GtCY^xIA`d^TmqvunaEo4*1?@}*Rf+ou=f6RPqj c@*8`|-_;i<-us$5J;e&Y@zkeYqR#^V0!=)3-~a#s 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} -- 2.39.5