X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Fjava%2Forg%2Fmxchange%2Fpizzaapplication%2Fbeans%2Fcountry%2FPizzaCountryWebApplicationBean.java;h=623ced5195255b5d4e381f1c5e3eb69e856b0897;hb=2e469aa632779932cdd6317a61b3da8f219560be;hp=c63c393d24c13f13eed9feb4915c36ccfedbab12;hpb=16c517e78c186ed0ff9d891e6da4e115915a0621;p=pizzaservice-war.git diff --git a/src/java/org/mxchange/pizzaapplication/beans/country/PizzaCountryWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/country/PizzaCountryWebApplicationBean.java index c63c393d..623ced51 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/country/PizzaCountryWebApplicationBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/country/PizzaCountryWebApplicationBean.java @@ -16,10 +16,12 @@ */ package org.mxchange.pizzaapplication.beans.country; +import java.text.MessageFormat; import java.util.Collections; import java.util.List; import javax.annotation.PostConstruct; import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.event.Observes; import javax.faces.view.facelets.FaceletException; import javax.inject.Named; import javax.naming.Context; @@ -27,13 +29,14 @@ import javax.naming.InitialContext; import javax.naming.NamingException; import org.mxchange.jcountry.data.Country; import org.mxchange.jcountry.data.CountrySingletonBeanRemote; +import org.mxchange.jcountry.events.AdminAddedCountryEvent; /** * A country bean *

* @author Roland Haeder */ -@Named ("country") +@Named ("countryController") @ApplicationScoped public class PizzaCountryWebApplicationBean implements PizzaCountryWebApplicationController { @@ -62,13 +65,34 @@ public class PizzaCountryWebApplicationBean implements PizzaCountryWebApplicatio Context context = new InitialContext(); // Try to lookup the bean - this.countryBean = (CountrySingletonBeanRemote) context.lookup("java:global/PizzaService-ejb/country!org.mxchange.jcountry.data.AddressbookCountrySingletonBeanLocal"); //NOI18N + this.countryBean = (CountrySingletonBeanRemote) context.lookup("java:global/PizzaService-ejb/country!org.mxchange.jcountry.data.CountrySingletonBeanRemote"); //NOI18N } catch (final NamingException ex) { // Continue to throw throw new FaceletException(ex); } } + @Override + public void afterAdminAddedCountry (@Observes final AdminAddedCountryEvent event) { + // Is all valid? + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getAddedCountry() == null) { + // Throw again ... + throw new NullPointerException("event.addedCountry is null"); //NOI18N + } else if (event.getAddedCountry().getCountryId() == null) { + // And again ... + throw new NullPointerException("event.addedCountry.countryId is null"); //NOI18N + } else if (event.getAddedCountry().getCountryId() < 1) { + // Id is invalid + throw new IllegalArgumentException(MessageFormat.format("event.addedCountry.countryId={0} is not valid.", event.getAddedCountry().getCountryId())); //NOI18N + } + + // Add the event + this.countryList.add(event.getAddedCountry()); + } + @Override public List allCountries () { // Return "cached" version