empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1457757 - in /empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2: controls/InputControl.java controls/TextInputControl.java utils/TagEncodingHelper.java
Date Mon, 18 Mar 2013 13:26:56 GMT
Author: doebele
Date: Mon Mar 18 13:26:55 2013
New Revision: 1457757

URL: http://svn.apache.org/r1457757
Log:
EMPIREDB-177
JSF2: allow custom date pattern and show hint with input control

Modified:
    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/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/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=1457757&r1=1457756&r2=1457757&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
Mon Mar 18 13:26:55 2013
@@ -445,14 +445,24 @@ public abstract class InputControl
     {
         // default implementation
         int count = parent.getChildCount(); 
-        if (count!=1)
+        if (count<1)
             return null;
-        // the input
-        UIComponent inp = parent.getChildren().get(0);
-        if (!(inp instanceof UIInput))
-            throw new UnexpectedReturnValueException(inp, "comp.getChildren().get(0)"); 
-        // OK
-        return (UIInput)inp;
+        // find the UIInput component (only one allowed)
+        UIInput inp = null;
+        for (int i=0; i<count; i++)
+        {	// check UIInput 
+        	UIComponent comp = parent.getChildren().get(i);
+	        if (comp instanceof UIInput)
+	        {	if (inp!=null)
+		        	throw new UnexpectedReturnValueException(comp, "comp.getChildren().get("+String.valueOf(i)+")");
+		        inp = (UIInput)comp;
+	        }
+        }
+        // No UIInput found
+        if (inp==null)
+        	throw new UnexpectedReturnValueException(null, "comp.getChildren().get()");
+        // done
+        return inp;
     }
 
     protected void copyAttributes(UIComponent parent, InputInfo ii, UIInput input, String
additonalStyle)
@@ -487,7 +497,7 @@ public abstract class InputControl
 
     protected final void copyAttributes(UIComponent parent, InputInfo ii, UIInput input)
     {
-        copyAttributes(parent, ii, input, null);
+        copyAttributes(parent, ii, input, (ii.isRequired() ? "eInpReq" : null));
     }
 
     protected void copyAttribute(InputInfo ii, UIInput input, String name)

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=1457757&r1=1457756&r2=1457757&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 Mar 18 13:26:55 2013
@@ -23,6 +23,7 @@ import java.sql.Timestamp;
 import java.text.DateFormat;
 import java.text.NumberFormat;
 import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.Currency;
 import java.util.Date;
 import java.util.List;
@@ -30,6 +31,8 @@ import java.util.Locale;
 
 import javax.faces.component.UIComponent;
 import javax.faces.component.html.HtmlInputText;
+import javax.faces.component.html.HtmlOutputText;
+import javax.faces.component.html.HtmlPanelGroup;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
 
@@ -41,6 +44,7 @@ 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.apache.empire.jsf2.utils.TagEncodingHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -96,6 +100,19 @@ public class TextInputControl extends In
                 input.setMaxlength(maxLength);
             // add
             compList.add(input);
+
+            // add unit
+            String unit = getUnitString(ii);
+            if (StringUtils.isNotEmpty(unit)) 
+            {	// add the unit
+	        	compList.add(createUnitLabel("eUnit", ii, unit));
+            }
+            // add hint
+            String hint = StringUtils.toString(ii.getAttribute("hint"));
+            if (StringUtils.isNotEmpty(hint) && !ii.isDisabled()) 
+            {	// add the hint (if not an empty string!)
+        		compList.add(createUnitLabel("eInputHint", ii, hint));
+            }
         } 
         else
         {   // check type
@@ -121,6 +138,18 @@ public class TextInputControl extends In
         setInputValue(input, ii);
     }
     
+    protected UIComponent createUnitLabel(String tagStyle, InputInfo ii, String value)
+    {
+        HtmlOutputText text = new HtmlOutputText();
+        text.setValue(value);
+        // wrap
+        HtmlPanelGroup span = new HtmlPanelGroup();
+        String styleClass = TagEncodingHelper.getTagStyleClass(tagStyle, TagEncodingHelper.getDataTypeClass(ii.getColumn().getDataType()),
null, null);
+        span.getAttributes().put("styleClass", styleClass);
+        span.getChildren().add(text);
+        return span;
+    }
+    
     // ------- parsing -------
 
     @Override
@@ -455,22 +484,31 @@ public class TextInputControl extends In
     
     protected DateFormat getDateFormat(DataType dataType, ValueInfo vi, Column column)
     {
-        int type = DateFormat.MEDIUM;
+        String pattern = null;
+        int type = DateFormat.DEFAULT;
         // 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))
+            if (StringUtils.compareEqual(format, "full", true))
+               type=DateFormat.FULL; 
+            else if (StringUtils.compareEqual(format, "medium", true))
+               type=DateFormat.MEDIUM; 
+            else if (StringUtils.compareEqual(format, "short", true))
                type=DateFormat.SHORT; 
             else if (StringUtils.compareEqual(format, "long", true))
-               type=DateFormat.LONG; 
+               type=DateFormat.LONG;
+            else 
+               pattern = format;
         }
         // return date formatter
         DateFormat df;
-        if (dataType==DataType.DATE)
-            df = DateFormat.getDateInstance(type, vi.getLocale());
+        if (StringUtils.isNotEmpty(pattern))
+	        df = new SimpleDateFormat(pattern, vi.getLocale());
+        else if (dataType==DataType.DATE)
+	        df = DateFormat.getDateInstance(type, vi.getLocale());
         else
-            df = DateFormat.getDateTimeInstance(type, type, vi.getLocale());
+        	df = DateFormat.getDateTimeInstance(type, type, vi.getLocale());
         return df;
     }
 

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=1457757&r1=1457756&r2=1457757&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
Mon Mar 18 13:26:55 2013
@@ -1326,7 +1326,7 @@ public class TagEncodingHelper implement
     
     /* ********************** CSS-generation ********************** */
 
-    public static String getTagStyleClass(String tagCssStyle, String typeClass, String addlStyle,
String userStyle)
+    public static final String getTagStyleClass(String tagCssStyle, String typeClass, String
addlStyle, String userStyle)
     {
         // tag and type style class
         if (StringUtils.isEmpty(userStyle) && StringUtils.isEmpty(addlStyle))
@@ -1356,7 +1356,7 @@ public class TagEncodingHelper implement
     public static final String CSS_DATA_TYPE_DATE     = " eTypeDate";
     public static final String CSS_DATA_TYPE_BOOL     = " eTypeBool";
 
-    private static String getDataTypeClass(DataType type)
+    public static final String getDataTypeClass(DataType type)
     {
         switch (type)
         {



Mime
View raw message