]> git.mxchange.org Git - jfinancials-war.git/commitdiff
Continued:
authorRoland Haeder <roland@mxchange.org>
Mon, 12 Oct 2015 11:31:16 +0000 (13:31 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 12 Oct 2015 11:31:16 +0000 (13:31 +0200)
- added converter for country instance
- added converter for SMS provider (cell phone)
- enabled converts in template
- updated jar(s)
Signed-off-by:Roland Häder <roland@mxchange.org>

lib/jcontacts-business-core.jar
lib/jcontacts-core.jar
lib/jphone-core.jar
src/java/org/mxchange/jcountry/data/CountryConverter.java [new file with mode: 0644]
src/java/org/mxchange/jphone/phonenumbers/smsprovider/SmsProviderConverter.java [new file with mode: 0644]
web/WEB-INF/templates/generic/form_personal_data.tpl

index a5e07b705621de173e1b4ffe1e88e933a836a1e9..fbe26f77d5b6b551c3c196627875d93f84c8d915 100644 (file)
Binary files a/lib/jcontacts-business-core.jar and b/lib/jcontacts-business-core.jar differ
index d1599646edb47bc737ba6e93b27c1d992ed0ed88..b977044176df140d0a842f3cd87d2d9913325158 100644 (file)
Binary files a/lib/jcontacts-core.jar and b/lib/jcontacts-core.jar differ
index 09d31d021f45e52b1f8bff4b13c78c01fc84571c..b8dca2dabf7a76459a987f1aa219cbae8f80a21f 100644 (file)
Binary files a/lib/jphone-core.jar and b/lib/jphone-core.jar differ
diff --git a/src/java/org/mxchange/jcountry/data/CountryConverter.java b/src/java/org/mxchange/jcountry/data/CountryConverter.java
new file mode 100644 (file)
index 0000000..e54de49
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2015 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcountry.data;
+
+import java.text.MessageFormat;
+import java.util.List;
+import java.util.Objects;
+import javax.annotation.PostConstruct;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.FacesConverter;
+import javax.inject.Inject;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.mxchange.addressbook.beans.country.CountryWebController;
+import org.mxchange.jcoreeelogger.beans.local.logger.Log;
+import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
+import org.mxchange.jphone.phonenumbers.smsprovider.CellphoneProvider;
+
+/**
+ * Converter for country instance
+ * <p>
+ * @author Roland Haeder
+ */
+@FacesConverter (forClass = CellphoneProvider.class, value = "country")
+public class CountryConverter implements Converter {
+
+       /**
+        * Category bean
+        */
+       @Inject
+       private CountryWebController countryController;
+
+       /**
+        * Logger instance
+        */
+       @Log
+       private LoggerBeanLocal loggerBeanLocal;
+
+       /**
+        * Initialization of this converter
+        */
+       @PostConstruct
+       public void init () {
+               // Try to get it
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Lookup logger
+                       this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N
+               } catch (final NamingException ex) {
+                       // Continue to throw it
+                       throw new RuntimeException("context.lookup() failed.", ex); //NOI18N
+               }
+       }
+
+       @Override
+       public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
+               // Trace message
+               this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: contect={0},component={1},submittedValue={2} - CALLED!", context, component, submittedValue)); //NOI18N
+
+               // Get full list
+               List<Country> countryList = this.countryController.allCountries();
+
+               // Is the value null or empty?
+               if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
+                       // Return null
+                       return null;
+               }
+
+               // Init value
+               Country country = null;
+
+               // Try this better
+               try {
+                       // Convert it to long
+                       Long countryId = Long.parseLong(submittedValue);
+
+                       // Category id should not be below 1
+                       assert (countryId > 0) : "countryId is smaller than one: " + countryId; //NOI18N
+
+                       // Debug message
+                       this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: countryId={0}", countryId)); //NOI18N
+
+                       // Try to find it
+                       for (final Country cntry : countryList) {
+                               // Is the id the same? (null-safe)
+                               if (Objects.equals(cntry.getCountryId(), countryId)) {
+                                       // Found it
+                                       country = cntry;
+                                       break;
+                               }
+                       }
+               } catch (final NumberFormatException ex) {
+                       // Log exception (maybe to much?)
+                       this.loggerBeanLocal.logException(ex);
+               }
+
+               // Trace message
+               this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: country={0} - EXIT!", country)); //NOI18N
+
+               // Return it
+               return country;
+       }
+
+       @Override
+       public String getAsString (final FacesContext context, final UIComponent component, final Object value) {
+               // Is the object null?
+               if ((null == value) || ((String.valueOf(value)).isEmpty())) {
+                       // Is null
+                       return ""; //NOI18N
+               } else if (!(value instanceof Country)) {
+                       // Not same interface
+                       throw new IllegalArgumentException(MessageFormat.format("value {0} does not implement Country.", value)); //NOI18N
+               }
+
+               // Return category id
+               return String.valueOf(((Country) value).getCountryId());
+       }
+
+}
diff --git a/src/java/org/mxchange/jphone/phonenumbers/smsprovider/SmsProviderConverter.java b/src/java/org/mxchange/jphone/phonenumbers/smsprovider/SmsProviderConverter.java
new file mode 100644 (file)
index 0000000..10fc783
--- /dev/null
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2015 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jphone.phonenumbers.smsprovider;
+
+import java.text.MessageFormat;
+import java.util.List;
+import java.util.Objects;
+import javax.annotation.PostConstruct;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.FacesConverter;
+import javax.inject.Inject;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.mxchange.addressbook.beans.smsprovider.SmsProviderWebController;
+import org.mxchange.jcoreeelogger.beans.local.logger.Log;
+import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
+
+/**
+ * Converter for SMS provider instance
+ * <p>
+ * @author Roland Haeder
+ */
+@FacesConverter (forClass = CellphoneProvider.class, value = "cellphoneCarrier")
+public class SmsProviderConverter implements Converter {
+
+       /**
+        * Category bean
+        */
+       @Inject
+       private SmsProviderWebController providerController;
+
+       /**
+        * Logger instance
+        */
+       @Log
+       private LoggerBeanLocal loggerBeanLocal;
+
+       /**
+        * Initialization of this converter
+        */
+       @PostConstruct
+       public void init () {
+               // Try to get it
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Lookup logger
+                       this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N
+               } catch (final NamingException ex) {
+                       // Continue to throw it
+                       throw new RuntimeException("context.lookup() failed.", ex); //NOI18N
+               }
+       }
+
+       @Override
+       public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
+               // Trace message
+               this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: contect={0},component={1},submittedValue={2} - CALLED!", context, component, submittedValue)); //NOI18N
+
+               // Get full list
+               List<SmsProvider> providerList = this.providerController.allSmsProvider();
+
+               // Is the value null or empty?
+               if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
+                       // Return null
+                       return null;
+               }
+
+               // Init value
+               SmsProvider provider = null;
+
+               // Try this better
+               try {
+                       // Convert it to long
+                       Long providerId = Long.parseLong(submittedValue);
+
+                       // Category id should not be below 1
+                       assert (providerId > 0) : "providerId is smaller than one: " + providerId; //NOI18N
+
+                       // Debug message
+                       this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: providerId={0}", providerId)); //NOI18N
+
+                       // Try to find it
+                       for (final SmsProvider prov : providerList) {
+                               // Is the id the same? (null-safe)
+                               if (Objects.equals(prov.getProviderId(), providerId)) {
+                                       // Found it
+                                       provider = prov;
+                                       break;
+                               }
+                       }
+               } catch (final NumberFormatException ex) {
+                       // Log exception (maybe to much?)
+                       this.loggerBeanLocal.logException(ex);
+               }
+
+               // Trace message
+               this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: provider={0} - EXIT!", provider)); //NOI18N
+
+               // Return it
+               return provider;
+       }
+
+       @Override
+       public String getAsString (final FacesContext context, final UIComponent component, final Object value) {
+               // Is the object null?
+               if ((null == value) || ((String.valueOf(value)).isEmpty())) {
+                       // Is null
+                       return ""; //NOI18N
+               } else if (!(value instanceof SmsProvider)) {
+                       // Not same interface
+                       throw new IllegalArgumentException(MessageFormat.format("value {0} does not implement SmsProvider.", value)); //NOI18N
+               }
+
+               // Return category id
+               return String.valueOf(((SmsProvider) value).getProviderId());
+       }
+
+}
index c0314bbbe00db11b9e8aa9ac3c00637439721b8b..c54746b3a33db5b89fd05b5dabb20a7eeb4476d6 100644 (file)
                                </div>
 
                                <div class="table_right">
-                                       <h:selectOneMenu class="select" id="country" value="#{userController.country}">
+                                       <h:selectOneMenu class="select" id="country" value="#{userController.country}" converter="country">
                                                <f:selectItem itemValue="" itemLabel="#{msg.NONE_SELECTED}" />
                                                <f:selectItems value="#{country.allCountries()}" var="c" itemValue="#{c}" itemLabel="#{c.countryCode} (#{msg[c.countryI18nkey]})" />
                                        </h:selectOneMenu>
                                </div>
 
                                <div class="table_right">
-                                       <h:selectOneMenu class="select" id="phoneCountryCode" value="#{userController.phoneCountry}">
+                                       <h:selectOneMenu class="select" id="phoneCountryCode" value="#{userController.phoneCountry}" converter="country">
                                                <f:selectItem itemValue="" itemLabel="#{msg.NONE_SELECTED}" />
                                                <f:selectItems value="#{country.allCountries()}" var="c" itemValue="#{c}" itemLabel="#{c.countryAbroadDialPrefix}#{c.countryPhoneCode}" />
                                        </h:selectOneMenu>
                                </div>
 
                                <div class="table_right">
-                                       <h:selectOneMenu class="select" id="faxCountryCode" value="#{userController.faxCountry}">
+                                       <h:selectOneMenu class="select" id="faxCountryCode" value="#{userController.faxCountry}" converter="country">
                                                <f:selectItem itemValue="" itemLabel="#{msg.NONE_SELECTED}" />
                                                <f:selectItems value="#{country.allCountries()}" var="c" itemValue="#{c}" itemLabel="#{c.countryAbroadDialPrefix}#{c.countryPhoneCode}" />
                                        </h:selectOneMenu>
                                </div>
 
                                <div class="table_right">
-                                       <h:selectOneMenu class="select" id="cellphoneCarrier" value="#{userController.cellphoneCarrier}">
+                                       <h:selectOneMenu class="select" id="cellphoneCarrier" value="#{userController.cellphoneCarrier}" converter="cellphoneCarrier">
                                                <f:selectItem itemValue="" itemLabel="#{msg.NONE_SELECTED}" />
                                                <f:selectItems value="#{cellphone.allSmsProvider()}" var="p" itemValue="#{p}" itemLabel="#{p.country.countryLocalDialPrefix}#{p.providerDialPrefix} (#{p.providerName})" />
                                        </h:selectOneMenu>