empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1363318 - in /empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2: components/SelectTag.java controls/SelectInputControl.java controls/TextInputControl.java
Date Thu, 19 Jul 2012 12:53:55 GMT
Author: doebele
Date: Thu Jul 19 12:53:55 2012
New Revision: 1363318

URL: http://svn.apache.org/viewvc?rev=1363318&view=rev
Log:
EMPIREDB-141
Use SelectInputControl for SelectTag in jsf2 extensions

Modified:
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/SelectTag.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

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/SelectTag.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/SelectTag.java?rev=1363318&r1=1363317&r2=1363318&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/SelectTag.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/SelectTag.java
Thu Jul 19 12:53:55 2012
@@ -34,6 +34,8 @@ import org.apache.empire.commons.Options
 import org.apache.empire.commons.StringUtils;
 import org.apache.empire.jsf2.app.FacesUtils;
 import org.apache.empire.jsf2.app.TextResolver;
+import org.apache.empire.jsf2.controls.InputControlManager;
+import org.apache.empire.jsf2.controls.SelectInputControl;
 import org.apache.empire.jsf2.utils.TagEncodingHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -148,8 +150,8 @@ public class SelectTag extends UIInput i
 
     private UIInput createSelectOneMenu(TextResolver textResolver)
     {
-
-        HtmlSelectOneMenu input = new HtmlSelectOneMenu();
+        SelectInputControl control = (SelectInputControl)InputControlManager.getControl(SelectInputControl.NAME);
+        HtmlSelectOneMenu input = control.createMenuComponent(this);
         // css style
         String userStyle = StringUtils.toString(getAttributes().get("styleClass"));
         String cssStyle  = TagEncodingHelper.getTagStyleClass("eSelect", null, null, userStyle);

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=1363318&r1=1363317&r2=1363318&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
Thu Jul 19 12:53:55 2012
@@ -53,6 +53,18 @@ public class SelectInputControl extends 
         this(javax.faces.component.html.HtmlSelectOneMenu.class);
     }
     
+    /* for SelectTag (when no column is available) */
+    public HtmlSelectOneMenu createMenuComponent(UIComponent parent)
+    {
+        try {
+            return inputComponentClass.newInstance();
+        } catch (InstantiationException e1) {
+            throw new InternalException(e1);
+        } catch (IllegalAccessException e2) {
+            throw new InternalException(e2);
+        }
+    }
+    
     @Override
     protected void createInputComponents(UIComponent parent, InputInfo ii, FacesContext context,
List<UIComponent> compList)
     {

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=1363318&r1=1363317&r2=1363318&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
Thu Jul 19 12:53:55 2012
@@ -48,6 +48,9 @@ public class TextInputControl extends In
 
     public static final String FORMAT_UNIT = "unit:";
     public static final String FORMAT_UNIT_ATTRIBUTE = "format:unit";
+
+    public static final String DATE_FORMAT = "date-format:";
+    public static final String DATE_FORMAT_ATTRIBUTE = "format:date";
     
     private Class<? extends javax.faces.component.html.HtmlInputText> inputComponentClass;
     
@@ -211,7 +214,7 @@ public class TextInputControl extends In
             if (dataType== DataType.DATETIME && hasFormatOption(vi, "notime"))
                 dataType = DataType.DATE;
             // Now format the date according to the user's locale
-            DateFormat df = getDateFormat(dataType, vi.getLocale(), column);
+            DateFormat df = getDateFormat(dataType, vi, column);
             return df.format(value);
         }
         /*
@@ -380,13 +383,24 @@ public class TextInputControl extends In
         return nf; 
     }
     
-    protected DateFormat getDateFormat(DataType dataType, Locale locale, Column column)
+    protected DateFormat getDateFormat(DataType dataType, ValueInfo vi, Column column)
     {
+        int type = DateFormat.MEDIUM;
+        // Is unit supplied as a format option
+        String format = getFormatString(vi, DATE_FORMAT, DATE_FORMAT_ATTRIBUTE);
+        if (format!=null)
+        {   // format has been provided
+            if (StringUtils.compareEqual(format, "short", true))
+               type=DateFormat.SHORT; 
+            else if (StringUtils.compareEqual(format, "long", true))
+               type=DateFormat.LONG; 
+        }
+        // return date formatter
         DateFormat df;
         if (dataType==DataType.DATE)
-            df = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
+            df = DateFormat.getDateInstance(type, vi.getLocale());
         else
-            df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, locale);
+            df = DateFormat.getDateTimeInstance(type, type, vi.getLocale());
         return df;
     }
 



Mime
View raw message