empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1386884 - /empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextInputControl.java
Date Mon, 17 Sep 2012 22:29:29 GMT
Author: doebele
Date: Mon Sep 17 22:29:29 2012
New Revision: 1386884

URL: http://svn.apache.org/viewvc?rev=1386884&view=rev
Log:
EMPIREDB-157 
JSF2 calculate text input maxlength from data type

Modified:
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextInputControl.java

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=1386884&r1=1386883&r2=1386884&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
Mon Sep 17 22:29:29 2012
@@ -38,6 +38,7 @@ import org.apache.empire.commons.Options
 import org.apache.empire.commons.StringUtils;
 import org.apache.empire.data.Column;
 import org.apache.empire.data.DataType;
+import org.apache.empire.db.DBColumn;
 import org.apache.empire.exceptions.InternalException;
 import org.apache.empire.exceptions.UnexpectedReturnValueException;
 import org.slf4j.Logger;
@@ -90,20 +91,7 @@ public class TextInputControl extends In
             // language
             input.setLang(ii.getLocale().getLanguage());
             // maxlength
-            int maxLength = 0;
-            DataType type = ii.getColumn().getDataType();
-            switch(type)
-            {
-                case CHAR:
-                case TEXT:
-                     maxLength = ((int) Math.round(ii.getColumn().getSize()));
-                     break;
-                case DECIMAL:
-                     maxLength = ((int) Math.round(ii.getColumn().getSize()))+1;
-                     break;
-                default:
-                     maxLength = 0;
-            }
+            int maxLength = getMaxInputLength(ii.getColumn());
             if (maxLength>0)
                 input.setMaxlength(maxLength);
             // add
@@ -355,6 +343,7 @@ public class TextInputControl extends In
             }
         }
     }
+    */
     
     // ------- Input Helpers -------
 
@@ -362,18 +351,34 @@ public class TextInputControl extends In
     {
         // cast to DBTableColumn 
         DataType type = col.getDataType();
+        if (type==DataType.CHAR ||
+            type==DataType.TEXT)
+            return (int)Math.round(col.getSize());
         if (type==DataType.AUTOINC ||
             type==DataType.INTEGER)
             return 10; 
-        if (type==DataType.DOUBLE)
+        if (type==DataType.FLOAT)
             return 18;
         if (type==DataType.DECIMAL)
-        {   
+        {   // check precision and scale
             double size = col.getSize();
-            int len = (int)size;
-            size = (size - len)*10;   // Ganzahlanteil
-            if (((int)size)>0)
-                len += ((int)size)+1; // Dezimaltrenner plus Nachkommastellen
+            int prec  = (int)Math.round(size);
+            if (prec == 0)
+                return 0;
+            int len = prec;
+            // scale
+            int scale =((int)(size*10)-(prec*10));
+            if (scale>0)
+                len++; // Dezimaltrenner
+            // thousand separator ?
+            Object groupSep = col.getAttribute(InputControl.NUMBER_GROUPSEP_ATTRIBUTE);
+            if (groupSep!=null && ObjectUtils.getBoolean(groupSep))
+                len += (prec/3);
+            // sign?
+            Object minVal = col.getAttribute(DBColumn.DBCOLATTR_MINVALUE);
+            if (minVal==null || ObjectUtils.getInteger(minVal)<0)
+                len++; // Vorzeichen
+            // fertig
             return len;
         }
         if (type==DataType.BOOL)
@@ -384,10 +389,10 @@ public class TextInputControl extends In
             return 16;
         if (type==DataType.CLOB)
             return 0; // unlimited (use 0x7FFFFFFF instead?)
-        // Default
-        return (int)col.getSize();
+        // undefined!
+        log.info("No max-length available for data type {}.", type);
+        return 0;
     }
-    */
     
     protected DataType getValueType(Object value, DataType desiredType)
     {



Mime
View raw message