]> git.mxchange.org Git - jjobs-war.git/blobdiff - src/java/org/mxchange/jjobs/beans/country/JobsAdminCountryWebRequestBean.java
Please cherry-pick:
[jjobs-war.git] / src / java / org / mxchange / jjobs / beans / country / JobsAdminCountryWebRequestBean.java
index 7db105eea3fad994ecf372895660864387376553..98a5a7c387808bb35b510189525e0d2a8961b5e5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 - 2018 Free Software Foundation
+ * Copyright (C) 2016 - 2020 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
  */
 package org.mxchange.jjobs.beans.country;
 
-import java.util.Iterator;
-import java.util.List;
 import java.util.Objects;
 import javax.ejb.EJB;
 import javax.enterprise.context.RequestScoped;
 import javax.enterprise.event.Event;
 import javax.enterprise.inject.Any;
-import javax.faces.view.facelets.FaceletException;
+import javax.faces.FacesException;
 import javax.inject.Inject;
 import javax.inject.Named;
 import org.mxchange.jcountry.events.added.AdminAddedCountryEvent;
@@ -33,6 +31,7 @@ import org.mxchange.jcountry.model.data.AdminCountrySessionBeanRemote;
 import org.mxchange.jcountry.model.data.Country;
 import org.mxchange.jcountry.model.data.CountryData;
 import org.mxchange.jjobs.beans.BaseJobsBean;
+import org.mxchange.jjobs.beans.country.list.JobsCountryListWebViewController;
 
 /**
  * An administrative country bean
@@ -71,12 +70,6 @@ public class JobsAdminCountryWebRequestBean extends BaseJobsBean implements Jobs
         */
        private String countryCode;
 
-       /**
-        * Regular country controller
-        */
-       @Inject
-       private JobsCountryWebRequestController countryController;
-
        /**
         * Local dial prefix
         */
@@ -92,6 +85,12 @@ public class JobsAdminCountryWebRequestBean extends BaseJobsBean implements Jobs
         */
        private Boolean countryIsLocalPrefixRequired;
 
+       /**
+        * Regular country controller
+        */
+       @Inject
+       private JobsCountryListWebViewController countryListController;
+
        /**
         * Phone code
         */
@@ -126,7 +125,7 @@ public class JobsAdminCountryWebRequestBean extends BaseJobsBean implements Jobs
                // Does it already exist?
                if (this.isCountryAdded(country)) {
                        // Yes, then abort here
-                       throw new FaceletException(new CountryAlreadyAddedException(country));
+                       throw new FacesException(new CountryAlreadyAddedException(country));
                }
 
                // Init variable
@@ -137,7 +136,7 @@ public class JobsAdminCountryWebRequestBean extends BaseJobsBean implements Jobs
                        updatedCountry = this.adminCountryBean.addCountry(country);
                } catch (final CountryAlreadyAddedException ex) {
                        // Throw again
-                       throw new FaceletException(ex);
+                       throw new FacesException(ex);
                }
 
                // Fire event
@@ -282,19 +281,10 @@ public class JobsAdminCountryWebRequestBean extends BaseJobsBean implements Jobs
                // Default is not found
                boolean isAdded = false;
 
-               // Now get whole ist
-               final List<Country> countries = this.countryController.allCountries();
-
-               // Get iterator from it
-               final Iterator<Country> iterator = countries.iterator();
-
                // Check whole list
-               while (iterator.hasNext()) {
-                       // Get next country
-                       final Country next = iterator.next();
-
+               for (final Country currentCountry : this.countryListController.getAllCountries()) {
                        // Is country code or i18n the same?
-                       if ((Objects.equals(country.getCountryCode(), next.getCountryCode())) || (Objects.equals(country.getCountryI18nKey(), next.getCountryI18nKey()))) {
+                       if ((Objects.equals(country.getCountryCode(), currentCountry.getCountryCode())) || (Objects.equals(country.getCountryI18nKey(), currentCountry.getCountryI18nKey()))) {
                                // Yes, then abort search
                                isAdded = true;
                                break;