empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1375656 - in /empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2: controls/CheckboxInputControl.java controls/InputControl.java controls/SelectInputControl.java controls/TextInputControl.java utils/TagEncodingHelper.java
Date Tue, 21 Aug 2012 16:47:50 GMT
Author: doebele
Date: Tue Aug 21 16:47:49 2012
New Revision: 1375656

URL: http://svn.apache.org/viewvc?rev=1375656&view=rev
Log:
EMPIREDB-161
Input value formatting and parsing according to user locale

Modified:
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/CheckboxInputControl.java
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/SelectInputControl.java
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextInputControl.java
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/CheckboxInputControl.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/CheckboxInputControl.java?rev=1375656&r1=1375655&r2=1375656&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/CheckboxInputControl.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/CheckboxInputControl.java
Tue Aug 21 16:47:49 2012
@@ -76,15 +76,9 @@ public class CheckboxInputControl extend
     }
     
     @Override
-    public Object getInputValue(UIComponent comp, InputInfo ii, boolean submitted)
+    protected Object parseInputValue(String value, InputInfo ii)
     {
-        Object value = super.getInputValue(comp, ii, submitted);
-        // Convert to boolean
-        if (!ObjectUtils.isEmpty(value))
-        {
-            return ObjectUtils.getBoolean(value);
-        }
-        return value;
+        return ObjectUtils.getBoolean(value);
     }
     
 }

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java?rev=1375656&r1=1375655&r2=1375656&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java
Tue Aug 21 16:47:49 2012
@@ -267,21 +267,25 @@ public abstract class InputControl
         
         // Get value from Input
         Object value = (submitted) ? input.getSubmittedValue() : input.getValue();
-        if (submitted && value!=null)
+        if (submitted)
         {
-            // if (!ObjectUtils.compareEqual(value, input.getLocalValue())
-            // {
-            // }
-            
-            FacesContext fc = FacesContext.getCurrentInstance();
-            Map<String, Object> reqMap = fc.getExternalContext().getRequestMap();
-            // Save submitted value
-            String clientId = input.getClientId();
-            if (reqMap.containsKey(clientId))
+            if (value!=null) // && (!ObjectUtils.compareEqual(value, input.getLocalValue())
             {
-                log.warn("OOps, what is going on here?");
-            }            
-            reqMap.put(clientId, value);
+                FacesContext fc = FacesContext.getCurrentInstance();
+                Map<String, Object> reqMap = fc.getExternalContext().getRequestMap();
+                // Save submitted value
+                String clientId = input.getClientId();
+                if (reqMap.containsKey(clientId))
+                {
+                    log.warn("OOps, what is going on here?");
+                }            
+                reqMap.put(clientId, value);
+            }
+            // Convert
+            if ((value instanceof String) && ((String)value).length()>0)
+            {
+                return parseInputValue((String)value, ii);
+            }
         }
         return value;
     }
@@ -321,6 +325,7 @@ public abstract class InputControl
         }    
         else
         {   // Set the value
+            value = formatInputValue(value, ii);
             input.setValue(value);
         }    
     }    
@@ -335,6 +340,22 @@ public abstract class InputControl
         if (reqMap.containsKey(clientId))
             reqMap.remove(clientId);
     }    
+
+    /**
+     * Override this to format a value for output
+     * @param value
+     * @param ii
+     * @return
+     */
+    protected Object formatInputValue(Object value, InputInfo ii)
+    {
+        return value;
+    }
+    
+    protected Object parseInputValue(String value, InputInfo ii)
+    {
+        return value;
+    }
     
     /* validate 
     public boolean validateValue(UIComponent comp, InputInfo ii, FacesContext context)
@@ -442,7 +463,7 @@ public abstract class InputControl
      *
      * @return the formatted value 
      */
-    protected String formatValue(Object value, ValueInfo vi, boolean hasError)
+    protected String formatValue(Object value, ValueInfo vi)
     {
         // Lookup and Print value
         Options options = vi.getOptions();
@@ -472,8 +493,8 @@ public abstract class InputControl
      */
     protected final String formatValue(ValueInfo vi)
     {
-        boolean hasError = false; // ((vi instanceof InputInfo) && !((InputInfo)vi).isValid());

-        return formatValue(vi.getValue(true), vi, hasError);
+        // boolean hasError = ((vi instanceof InputInfo) && !((InputInfo)vi).isValid());

+        return formatValue(vi.getValue(true), vi);
     }
     
     /**

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/SelectInputControl.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/SelectInputControl.java?rev=1375656&r1=1375655&r2=1375656&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/SelectInputControl.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/SelectInputControl.java
Tue Aug 21 16:47:49 2012
@@ -130,13 +130,13 @@ public class SelectInputControl extends 
     }
 
     @Override
-    protected String formatValue(Object value, ValueInfo vi, boolean hasError)
+    protected String formatValue(Object value, ValueInfo vi)
     {
         // Lookup and Print value
         if (vi.getOptions()==null)
         {
             log.warn("Select field {} has no Option list attached!", vi.getColumn().getName());
-            return super.formatValue(value, vi, hasError);
+            return super.formatValue(value, vi);
         }
         // Check for Abbreviation
         if (hasFormatOption(vi, "short"))
@@ -155,7 +155,7 @@ public class SelectInputControl extends 
                 }
             }
         }
-        return super.formatValue(value, vi, hasError);
+        return super.formatValue(value, vi);
     }
     
     /*

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextInputControl.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextInputControl.java?rev=1375656&r1=1375655&r2=1375656&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextInputControl.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextInputControl.java
Tue Aug 21 16:47:49 2012
@@ -38,6 +38,7 @@ import org.apache.empire.data.Column;
 import org.apache.empire.data.DataType;
 import org.apache.empire.exceptions.InternalException;
 import org.apache.empire.exceptions.UnexpectedReturnValueException;
+import org.apache.empire.jsf2.controls.InputControl.InputInfo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -85,6 +86,8 @@ public class TextInputControl extends In
             }
             // once
             copyAttributes(parent, ii, input);
+            // language
+            input.setLang(ii.getLocale().getLanguage());
             // maxlength
             int maxLength = 0;
             DataType type = ii.getColumn().getDataType();
@@ -122,35 +125,40 @@ public class TextInputControl extends In
     
     // ------- parsing -------
 
-    /*
     @Override
-    protected Object parseValue(String value, Locale locale, Column column)
+    protected Object parseInputValue(String value, InputInfo ii)
     {
         // Check Data Type
+        Column column = ii.getColumn();
         DataType type = column.getDataType();
-        if (type==DataType.TEXT)
+        if (type.isText())
             return value;
         // Check other types
         if (type==DataType.INTEGER)
-        {   return parseInteger(value);
+        {   NumberFormat nf = NumberFormat.getIntegerInstance(ii.getLocale());
+            return parseNumber(value, nf);
         }
-        if (type==DataType.DECIMAL)
-        {   return parseDecimal(value, getNumberFormat(column.getDataType(), locale, column));
+        if (type==DataType.DECIMAL || type==DataType.FLOAT)
+        {   NumberFormat nf = NumberFormat.getNumberInstance(ii.getLocale());
+            return parseNumber(value, nf);
         }
         if (type==DataType.DATE || type==DataType.DATETIME)
-        {   return parseDate(value, getDateFormat(column.getDataType(), locale, column));
+        {   return parseDate(value, getDateFormat(column.getDataType(), ii, column));
+        }
+        if (type==DataType.BOOL)
+        {   return ObjectUtils.getBoolean(value);
         }
         if (type==DataType.AUTOINC)
         {   // autoinc
             log.error("Autoinc-value cannot be changed.");
-            return NO_VALUE;
+            return null;
         }
         // Default
         return value;
     }
     
     // ------- validation -------
-
+    /*
     @Override
     protected Object validate(Object o, Locale locale, Column column, String s)
     {
@@ -175,7 +183,7 @@ public class TextInputControl extends In
     // ------- formatting -------
 
     @Override
-    protected String formatValue(Object value, ValueInfo vi, boolean hasError)
+    protected String formatValue(Object value, ValueInfo vi)
     {
         // Lookup and Print value
         Options options = vi.getOptions();
@@ -192,7 +200,7 @@ public class TextInputControl extends In
         {   // Try to use default value
             Object nullValue = getFormatOption(vi, FORMAT_NULL, FORMAT_NULL_ATTRIBUTE);
             if (nullValue!=null)
-                return formatValue(nullValue, vi, false);
+                return formatValue(nullValue, vi);
             // Empty String
             return "";
         }
@@ -234,6 +242,7 @@ public class TextInputControl extends In
         return escapeHTML(String.valueOf(value));
     }
 
+    /*
     protected String formatValue(ValueInfo vi, boolean appendUnit)
     {
         String text = super.formatValue(vi);
@@ -247,7 +256,21 @@ public class TextInputControl extends In
         }
         return text;
     }
+    */
 
+    @Override
+    protected Object formatInputValue(Object value, InputInfo ii)
+    {
+        if (value == null)
+            return value;
+        // Check options
+        Options options = ii.getOptions();
+        if (options != null && !options.isEmpty())
+            return value;
+        // Format
+        return formatValue(value, ii);
+    }
+    
     // ------- render -------
     
     /*
@@ -446,13 +469,7 @@ public class TextInputControl extends In
     
     // ------- value parsing -------
     
-    protected Object parseInteger(String s)
-    {
-        // Try to convert
-        return Integer.parseInt(s);
-    }
-    
-    protected Object parseDecimal(String s, NumberFormat nf)
+    protected Object parseNumber(String s, NumberFormat nf)
     {
         // Try to convert
         for (int i=0; i<s.length(); i++)

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java?rev=1375656&r1=1375655&r2=1375656&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
Tue Aug 21 16:47:49 2012
@@ -344,11 +344,21 @@ public class TagEncodingHelper implement
         if (getColumn() == null)
         	throw new NotSupportedException(this, "getInputControl");
         // Get Control from column
-        String controlType = column.getControlType();
+        String controlType = getTagAttribute("controlType");
+        if (controlType==null)
+        {   controlType = column.getControlType();
+            // Always use SelectInputControl
+            if (TextInputControl.NAME.equalsIgnoreCase(controlType))
+            {   Object attr = tag.getAttributes().get("options");
+                if (attr != null && (attr instanceof Options) && !((Options)attr).isEmpty())
+                    controlType = SelectInputControl.NAME;
+            }
+        }
+        // find control type
         if (StringUtils.isNotEmpty(controlType))
             control = InputControlManager.getControl(controlType);
         if (control == null)
-        { // Auto-detect
+        {   // Auto-detect
             if (getValueOptions()!=null)
                 controlType = SelectInputControl.NAME;
             else



Mime
View raw message