import java.util.List;
import java.util.Objects;
import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Any;
import javax.faces.view.facelets.FaceletException;
import javax.inject.Inject;
import javax.inject.Named;
import org.mxchange.jcountry.data.Country;
import org.mxchange.jcountry.data.CountryData;
import org.mxchange.jcountry.data.CountrySingletonBeanRemote;
+import org.mxchange.jcountry.events.AdminAddedCountryEvent;
+import org.mxchange.jcountry.events.AdminEventCountryAdded;
import org.mxchange.jcountry.exceptions.CountryAlreadyAddedException;
/**
@Inject
private PizzaCountryWebApplicationController countryController;
+ /**
+ * An event triggered when the administrator has added a country
+ */
+ @Inject
+ @Any
+ private Event<AdminAddedCountryEvent> addedCountryEvent;
+
/**
* Local dial prefix
*/
// Send country to bean
this.countryBean.addCountry(country);
+ // Fire event
+ this.addedCountryEvent.fire(new AdminEventCountryAdded(country));
+
// Clear bean
this.clear();
} catch (final CountryAlreadyAddedException ex) {
*/
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;
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
}
}
+ @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<Country> allCountries () {
// Return "cached" version
import java.io.Serializable;
import java.util.List;
import org.mxchange.jcountry.data.Country;
+import org.mxchange.jcountry.events.AdminAddedCountryEvent;
/**
* An interface for country beans
*/
List<Country> allCountries ();
+ /**
+ * Observing method when the event is fired that an administrator added a
+ * new country
+ * <p>
+ * @param event Event instance
+ */
+ void afterAdminAddedCountry (final AdminAddedCountryEvent event);
}