You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/06/29 01:18:57 UTC

svn commit: r958783 - in /myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom: calendar/ date/

Author: lu4242
Date: Mon Jun 28 23:18:57 2010
New Revision: 958783

URL: http://svn.apache.org/viewvc?rev=958783&view=rev
Log:
TOMAHAWK-1508 Find a way to convert between the model type required for the renderer, and the model-type that the backing-beans use for t:inputCalendar and t:inputDate

Added:
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/AbstractHtmlInputCalendarTag.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/DateBusinessConverter.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/DefaultDateBusinessConverter.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/HtmlInputCalendarTagHandler.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/date/AbstractHtmlInputDateTag.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/date/HtmlInputDateTagHandler.java
Modified:
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/AbstractHtmlInputCalendar.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/date/AbstractHtmlInputDate.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/date/HtmlDateRenderer.java

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/AbstractHtmlInputCalendar.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/AbstractHtmlInputCalendar.java?rev=958783&r1=958782&r2=958783&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/AbstractHtmlInputCalendar.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/AbstractHtmlInputCalendar.java Mon Jun 28 23:18:57 2010
@@ -75,6 +75,8 @@ import org.apache.myfaces.component.html
  *   name = "t:inputCalendar"
  *   class = "org.apache.myfaces.custom.calendar.HtmlInputCalendar"
  *   tagClass = "org.apache.myfaces.custom.calendar.HtmlInputCalendarTag"
+ *   tagSuperclass = "org.apache.myfaces.custom.calendar.AbstractHtmlInputCalendarTag"
+ *   tagHandler = "org.apache.myfaces.custom.calendar.HtmlInputCalendarTagHandler"
  * @since 1.1.7
  * @author Martin Marinschek (latest modification by $Author$)
  * @version $Revision$ $Date$
@@ -92,6 +94,14 @@ public abstract class AbstractHtmlInputC
         if (!UserRoleUtils.isVisibleOnUserRole(this)) return false;
         return super.isRendered();
     }
+    
+    /**
+     * 
+     * @JSFProperty stateHolder="true" inheritedTag="true"
+     */
+    public abstract DateBusinessConverter getDateBusinessConverter();
+    
+    public abstract void setDateBusinessConverter(DateBusinessConverter dateBusinessConverter);
         
     /**
      * CSS class to be used on the TR element for the header-row showing month and year.

Added: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/AbstractHtmlInputCalendarTag.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/AbstractHtmlInputCalendarTag.java?rev=958783&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/AbstractHtmlInputCalendarTag.java (added)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/AbstractHtmlInputCalendarTag.java Mon Jun 28 23:18:57 2010
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.custom.calendar;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
+import org.apache.myfaces.shared_tomahawk.util.ClassUtils;
+
+/**
+ * 
+ * @since 1.1.10
+ * @author Leonardo Uribe (latest modification by $Author: lu4242 $)
+ * @version $Revision: 691856 $ $Date: 2008-09-03 21:40:30 -0500 (mié, 03 sep 2008) $
+ */
+public abstract class AbstractHtmlInputCalendarTag extends 
+    org.apache.myfaces.generated.taglib.html.ext.HtmlInputTextTag
+{
+    
+    private String _dateBusinessConverter;
+    
+    public void setDateBusinessConverter(String dateBusinessConverter)
+    {
+        _dateBusinessConverter = dateBusinessConverter;
+    }
+
+    public void release() {
+        super.release();
+        _dateBusinessConverter = null;
+    }
+
+    /**
+     * Applies attributes to the tree component
+     */
+    protected void setProperties(UIComponent component) {
+        super.setProperties(component);
+        FacesContext context = FacesContext.getCurrentInstance();
+
+        org.apache.myfaces.custom.calendar.AbstractHtmlInputCalendar comp =
+            (org.apache.myfaces.custom.calendar.AbstractHtmlInputCalendar) component;
+        
+        if (_dateBusinessConverter != null)
+        {
+            if (isValueReference(_dateBusinessConverter))
+            {
+                ValueBinding vb = context.getApplication().createValueBinding(_dateBusinessConverter);
+                comp.setValueBinding("dateBusinessConverter", vb);
+            }
+            else
+            {
+                try
+                {
+                    Class clazz = ClassUtils.classForName(_dateBusinessConverter);
+                    comp.setDateBusinessConverter( (DateBusinessConverter) ClassUtils.newInstance(clazz));
+                }
+                catch(ClassNotFoundException e)
+                {
+                    throw new IllegalArgumentException("Class referenced in calendarConverter not found: "+_dateBusinessConverter);
+                }
+                catch(ClassCastException e)
+                {
+                    throw new IllegalArgumentException("Class referenced in calendarConverter is not instance of org.apache.myfaces.custom.calendar.CalendarConverter: "+_dateBusinessConverter);
+                }
+            }
+        }
+    }
+}

Added: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/DateBusinessConverter.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/DateBusinessConverter.java?rev=958783&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/DateBusinessConverter.java (added)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/DateBusinessConverter.java Mon Jun 28 23:18:57 2010
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.custom.calendar;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+/**
+ * 
+ * @since 1.1.10
+ * @author Leonardo Uribe (latest modification by $Author: lu4242 $)
+ * @version $Revision: 691856 $ $Date: 2008-09-03 21:40:30 -0500 (mié, 03 sep 2008) $
+ */
+public interface DateBusinessConverter
+{
+    /**
+     * 
+     * @param context
+     * @param component
+     * @param value
+     * @return
+     */
+    public Object getBusinessValue(FacesContext context,
+                       UIComponent component,
+                       java.util.Date value);
+
+    /**
+     *  
+     * @param context
+     * @param component
+     * @param value
+     * @return
+     */
+    public java.util.Date getDateValue(FacesContext context,
+                       UIComponent component,
+                       Object value);
+}

Added: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/DefaultDateBusinessConverter.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/DefaultDateBusinessConverter.java?rev=958783&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/DefaultDateBusinessConverter.java (added)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/DefaultDateBusinessConverter.java Mon Jun 28 23:18:57 2010
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.custom.calendar;
+
+import java.util.Date;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
+
+/**
+ * 
+ * @since 1.1.10
+ * @author Leonardo Uribe (latest modification by $Author: lu4242 $)
+ * @version $Revision: 691856 $ $Date: 2008-09-03 21:40:30 -0500 (mié, 03 sep 2008) $
+ */
+public class DefaultDateBusinessConverter implements DateBusinessConverter
+{
+
+    public Object getBusinessValue(FacesContext context, UIComponent component,
+            Date value)
+    {
+        ValueBinding vb = component.getValueBinding("value");
+        Class type = vb.getType(context); 
+        if (type != null)
+        {
+            if (java.sql.Date.class.isAssignableFrom(type))
+            {
+                return new java.sql.Date(value.getTime());
+            }
+        }
+        return value;
+    }
+
+    public Date getDateValue(FacesContext context, UIComponent component,
+            Object value)
+    {
+        if (value instanceof java.sql.Date)
+        {
+            //Convert to strict java.util.Date
+            return new Date(((java.sql.Date)value).getTime());
+        }
+        return (Date) value;
+    }
+}

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java?rev=958783&r1=958782&r2=958783&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java Mon Jun 28 23:18:57 2010
@@ -119,11 +119,62 @@ public class HtmlCalendarRenderer
         Locale currentLocale = facesContext.getViewRoot().getLocale();
         log.debug("current locale:" + currentLocale.toString());
 
+        String textValue;
+        
+        Converter converter = inputCalendar.getConverter();
+        Object submittedValue = inputCalendar.getSubmittedValue();
+        
         Date value;
 
+        if (submittedValue != null)
+        {
+            //Don't need to convert anything, the textValue is the same as the submittedValue
+            textValue = (String) submittedValue;
+            
+            if(textValue ==null || textValue.trim().length()==0 || textValue.equals(getHelperString(inputCalendar)))
+            {
+                value = null;
+            }
+            else
+            {
+                try
+                {
+                    String formatStr = CalendarDateTimeConverter.createJSPopupFormat(facesContext, inputCalendar.getPopupDateFormat());
+                    Calendar timeKeeper = Calendar.getInstance(currentLocale);
+                    int firstDayOfWeek = timeKeeper.getFirstDayOfWeek() - 1;
+                    org.apache.myfaces.dateformat.DateFormatSymbols symbols = new org.apache.myfaces.dateformat.DateFormatSymbols(currentLocale);
+    
+                    SimpleDateFormatter dateFormat = new SimpleDateFormatter(formatStr, symbols, firstDayOfWeek);
+                    value = dateFormat.parse(textValue);
+                }
+                catch (IllegalArgumentException illegalArgumentException)
+                {
+                    value = null;
+                }
+            }
+        }
+        else
+        {
+            if (converter == null)
+            {
+                CalendarDateTimeConverter defaultConverter = new CalendarDateTimeConverter();
+                
+                value = (Date) getDateBusinessConverter(inputCalendar).getDateValue(facesContext, component, inputCalendar.getValue());
+
+                textValue = defaultConverter.getAsString(facesContext, inputCalendar, value);
+            }
+            else
+            {
+                //Use converter to retrieve the value.
+                value = (Date) inputCalendar.getValue();
+                textValue = converter.getAsString(facesContext, inputCalendar, value);
+            }
+        }
+        /*
         try
         {
             // value = RendererUtils.getDateValue(inputCalendar);
+
             Converter converter = getConverter(inputCalendar);
             if (converter instanceof DateConverter)
             {
@@ -163,7 +214,7 @@ public class HtmlCalendarRenderer
         {
             value = null;
         }
-
+        */
 
         Calendar timeKeeper = Calendar.getInstance(currentLocale);
         timeKeeper.setTime(value!=null?value:new Date());
@@ -172,11 +223,11 @@ public class HtmlCalendarRenderer
 
         if(inputCalendar.isRenderAsPopup())
         {
-            renderPopup(facesContext, inputCalendar, value, timeKeeper, symbols);
+            renderPopup(facesContext, inputCalendar, textValue, timeKeeper, symbols);
         }
         else
         {
-            renderInline(facesContext, inputCalendar, value, timeKeeper, symbols);
+            renderInline(facesContext, inputCalendar, timeKeeper, symbols);
         }
 
         component.getChildren().removeAll(component.getChildren());
@@ -185,7 +236,7 @@ public class HtmlCalendarRenderer
     private void renderPopup(
             FacesContext facesContext, 
             HtmlInputCalendar inputCalendar,
-            Date value,
+            String value,
             Calendar timeKeeper,
             DateFormatSymbols symbols) throws IOException
     {
@@ -215,6 +266,8 @@ public class HtmlCalendarRenderer
         inputText.setHelpText(inputCalendar.getHelpText());
         inputText.setSelectText(true);
 
+        inputText.setValue(value);
+        /*
         if (value == null && inputCalendar.getSubmittedValue() != null)
         {
             inputText.setValue(inputCalendar.getSubmittedValue());
@@ -223,7 +276,7 @@ public class HtmlCalendarRenderer
         {
             inputText.setValue(getConverter(inputCalendar).getAsString(
                     facesContext,inputCalendar,value));
-        }
+        }*/
         inputText.setDisabled(inputCalendar.isDisabled());
         inputText.setReadonly(inputCalendar.isReadonly());
         inputText.setEnabledOnUserRole(inputCalendar.getEnabledOnUserRole());
@@ -289,7 +342,6 @@ public class HtmlCalendarRenderer
     private void renderInline(
             FacesContext facesContext, 
             HtmlInputCalendar inputCalendar,
-            Date value,
             Calendar timeKeeper,
             DateFormatSymbols symbols) throws IOException
     {
@@ -911,6 +963,16 @@ public class HtmlCalendarRenderer
         }
         return converter;
     }
+    
+    private DateBusinessConverter getDateBusinessConverter(AbstractHtmlInputCalendar component)
+    {
+        DateBusinessConverter dateBusinessConverter = component.getDateBusinessConverter(); 
+        if (dateBusinessConverter == null)
+        {
+            dateBusinessConverter = new DefaultDateBusinessConverter();
+        }
+        return dateBusinessConverter;
+    }
 
     private int mapCalendarDayToCommonDay(int day)
     {
@@ -1057,7 +1119,7 @@ public class HtmlCalendarRenderer
 
         RendererUtils.checkParamValidity(facesContext, component, HtmlInputCalendar.class);
 
-        String helperString = getHelperString(component);
+        //String helperString = getHelperString(component);
 
         if (!(component instanceof EditableValueHolder)) {
             throw new IllegalArgumentException("Component "
@@ -1072,20 +1134,20 @@ public class HtmlCalendarRenderer
         {
             String value = (String) paramMap.get(clientId);
 
-            if(!value.equalsIgnoreCase(helperString))
-            {
+            //if(!value.equalsIgnoreCase(helperString))
+            //{
                 ((EditableValueHolder) component).setSubmittedValue(value);
-            }
-            else
-            {
+            //}
+            //else
+            //{
                 // The field was initially filled with the "helper string", and has
                 // not been altered by the user so treat this as if null had been
                 // passed by the user.
                 //
                 // TODO: does this mean the target date is set to todays date?
                 // And how does this affect the "required" property?
-                ((EditableValueHolder) component).setSubmittedValue("");
-            }
+                //((EditableValueHolder) component).setSubmittedValue("");
+            //}
         }
         else
         {
@@ -1119,21 +1181,31 @@ public class HtmlCalendarRenderer
     {
         RendererUtils.checkParamValidity(facesContext, uiComponent, HtmlInputCalendar.class);
 
-        UIInput uiInput = (UIInput) uiComponent;
+        AbstractHtmlInputCalendar uiInput = (AbstractHtmlInputCalendar) uiComponent;
 
         Converter converter = uiInput.getConverter();
 
+        if (submittedValue != null && !(submittedValue instanceof String))
+        {
+            throw new IllegalArgumentException("Submitted value of type String expected");
+        }
+        
+        //Do not convert if submittedValue is helper string  
+        if(submittedValue != null && submittedValue.equals(getHelperString(uiComponent)))
+            return null;
+        
         if(converter==null)
         {
             converter = new CalendarDateTimeConverter();
+            
+            Date date = (Date) converter.getAsObject(facesContext, uiComponent, (String) submittedValue);
+            
+            return getDateBusinessConverter(uiInput).getBusinessValue(facesContext, uiComponent, date);
         }
-
-        if (submittedValue != null && !(submittedValue instanceof String))
+        else
         {
-            throw new IllegalArgumentException("Submitted value of type String expected");
+            return converter.getAsObject(facesContext, uiComponent, (String) submittedValue);
         }
-
-        return converter.getAsObject(facesContext, uiComponent, (String) submittedValue);
     }
 
     public interface DateConverter extends Converter

Added: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/HtmlInputCalendarTagHandler.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/HtmlInputCalendarTagHandler.java?rev=958783&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/HtmlInputCalendarTagHandler.java (added)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/calendar/HtmlInputCalendarTagHandler.java Mon Jun 28 23:18:57 2010
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.custom.calendar;
+
+import javax.faces.component.UIComponent;
+
+import org.apache.myfaces.shared_tomahawk.util.ClassUtils;
+
+import com.sun.facelets.FaceletContext;
+import com.sun.facelets.el.LegacyValueBinding;
+import com.sun.facelets.tag.MetaRule;
+import com.sun.facelets.tag.MetaRuleset;
+import com.sun.facelets.tag.Metadata;
+import com.sun.facelets.tag.MetadataTarget;
+import com.sun.facelets.tag.TagAttribute;
+import com.sun.facelets.tag.jsf.ComponentConfig;
+import com.sun.facelets.tag.jsf.html.HtmlComponentHandler;
+
+/**
+ * 
+ * @since 1.1.10
+ * @author Leonardo Uribe (latest modification by $Author: lu4242 $)
+ * @version $Revision: 691856 $ $Date: 2008-09-03 21:40:30 -0500 (mié, 03 sep 2008) $
+ */
+public class HtmlInputCalendarTagHandler extends HtmlComponentHandler
+{
+
+    public HtmlInputCalendarTagHandler(ComponentConfig config)
+    {
+        super(config);
+    }
+
+    protected MetaRuleset createMetaRuleset(Class type)
+    {
+        MetaRuleset m = super.createMetaRuleset(type);
+
+        m.addRule(DateBusinessConverterRule.INSTANCE);
+
+        return m;
+    }
+
+    public static class DateBusinessConverterRule extends MetaRule
+    {
+        public final static DateBusinessConverterRule INSTANCE = new DateBusinessConverterRule();
+
+        final static class LiteralConverterMetadata extends Metadata
+        {
+
+            private final Class dateBusinessConverterClass;
+
+            public LiteralConverterMetadata(String dateBusinessConverterClass)
+            {
+                try
+                {
+                    this.dateBusinessConverterClass = ClassUtils
+                            .classForName(dateBusinessConverterClass);
+                }
+                catch(ClassNotFoundException e)
+                {
+                    throw new IllegalArgumentException("Class referenced in calendarConverter not found: "+dateBusinessConverterClass);
+                }
+                catch(ClassCastException e)
+                {
+                    throw new IllegalArgumentException("Class referenced in calendarConverter is not instance of org.apache.myfaces.custom.calendar.CalendarConverter: "+dateBusinessConverterClass);
+                }
+            }
+
+            public void applyMetadata(FaceletContext ctx, Object instance)
+            {
+                ((AbstractHtmlInputCalendar) instance)
+                        .setDateBusinessConverter((DateBusinessConverter) ClassUtils
+                                .newInstance(dateBusinessConverterClass));
+            }
+        }
+
+        final static class DynamicConverterMetadata extends Metadata
+        {
+            private final TagAttribute attr;
+
+            public DynamicConverterMetadata(TagAttribute attr)
+            {
+                this.attr = attr;
+            }
+
+            public void applyMetadata(FaceletContext ctx, Object instance)
+            {
+                ((UIComponent) instance).setValueBinding("dateBusinessConverter",
+                        new LegacyValueBinding(attr.getValueExpression(ctx,
+                                DateBusinessConverter.class)));
+            }
+        }
+
+        public Metadata applyRule(String name, TagAttribute attribute,
+                MetadataTarget meta)
+        {
+            if (meta.isTargetInstanceOf(AbstractHtmlInputCalendar.class))
+            {
+                if ("dateBusinessConverter".equals(name)) {
+                    if (attribute.isLiteral()) {
+                        return new LiteralConverterMetadata(attribute.getValue());
+                    } else {
+                        return new DynamicConverterMetadata(attribute);
+                    }
+                }
+            }
+            return null;
+        }
+    }
+}

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/date/AbstractHtmlInputDate.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/date/AbstractHtmlInputDate.java?rev=958783&r1=958782&r2=958783&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/date/AbstractHtmlInputDate.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/date/AbstractHtmlInputDate.java Mon Jun 28 23:18:57 2010
@@ -35,6 +35,8 @@ import org.apache.myfaces.component.Forc
 import org.apache.myfaces.component.UserRoleAware;
 import org.apache.myfaces.component.UserRoleUtils;
 import org.apache.myfaces.component.html.util.HtmlComponentUtils;
+import org.apache.myfaces.custom.calendar.DateBusinessConverter;
+import org.apache.myfaces.custom.calendar.DefaultDateBusinessConverter;
 
 /**
  * Custom input control for dates and times. 
@@ -45,6 +47,9 @@ import org.apache.myfaces.component.html
  *   name = "t:inputDate"
  *   class = "org.apache.myfaces.custom.date.HtmlInputDate"
  *   tagClass = "org.apache.myfaces.custom.date.HtmlInputDateTag"
+ *   tagSuperclass = "org.apache.myfaces.custom.date.AbstractHtmlInputDateTag"
+ *   tagHandler = "org.apache.myfaces.custom.date.HtmlInputDateTagHandler"
+ *   
  * @since 1.1.7
  * @author Sylvain Vieujot (latest modification by $Author$)
  * @version $Revision$ $Date$
@@ -75,8 +80,18 @@ public abstract class AbstractHtmlInputD
     }
     
     public UserData getUserData(Locale currentLocale){
-        return new UserData((Date) getValue(), currentLocale, getTimeZone(), isAmpm(), getType());
-    }    
+        return new UserData((Date) getDateBusinessConverter(this).getDateValue(getFacesContext(), this, getValue()), currentLocale, getTimeZone(), isAmpm(), getType());
+    }
+    
+    private DateBusinessConverter getDateBusinessConverter(AbstractHtmlInputDate component)
+    {
+        DateBusinessConverter dateBusinessConverter = component.getDateBusinessConverter(); 
+        if (dateBusinessConverter == null)
+        {
+            dateBusinessConverter = new DefaultDateBusinessConverter();
+        }
+        return dateBusinessConverter;
+    }
 
     public static class UserData implements Serializable {
         private static final long serialVersionUID = -6507279524833267707L;
@@ -291,6 +306,14 @@ public abstract class AbstractHtmlInputD
     }
 
     /**
+     * 
+     * @JSFProperty stateHolder="true" inheritedTag="true"
+     */
+    public abstract DateBusinessConverter getDateBusinessConverter();
+    
+    public abstract void setDateBusinessConverter(DateBusinessConverter dateBusinessConverter);
+
+    /**
      * @JSFProperty
      */
     public abstract String getTimeZone();

Added: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/date/AbstractHtmlInputDateTag.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/date/AbstractHtmlInputDateTag.java?rev=958783&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/date/AbstractHtmlInputDateTag.java (added)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/date/AbstractHtmlInputDateTag.java Mon Jun 28 23:18:57 2010
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.custom.date;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
+import org.apache.myfaces.custom.calendar.DateBusinessConverter;
+import org.apache.myfaces.shared_tomahawk.util.ClassUtils;
+
+/**
+ * <p>
+ * HtmlTree tag.
+ * </p>
+ * @since 1.1.7
+ * @author <a href="mailto:oliver@rossmueller.com">Oliver Rossmueller </a>
+ * @version $Revision: 888604 $ $Date: 2004/10/13 11:50:58
+ */
+public abstract class AbstractHtmlInputDateTag extends 
+    org.apache.myfaces.shared_tomahawk.taglib.html.HtmlInputTextTag
+{
+    
+    private String _dateBusinessConverter;
+    
+    public void setDateBusinessConverter(String dateBusinessConverter)
+    {
+        _dateBusinessConverter = dateBusinessConverter;
+    }
+
+    public void release() {
+        super.release();
+        _dateBusinessConverter = null;
+    }
+
+    /**
+     * Applies attributes to the tree component
+     */
+    protected void setProperties(UIComponent component) {
+        super.setProperties(component);
+        FacesContext context = FacesContext.getCurrentInstance();
+
+        org.apache.myfaces.custom.date.AbstractHtmlInputDate comp =
+            (org.apache.myfaces.custom.date.AbstractHtmlInputDate) component;
+        
+        if (_dateBusinessConverter != null)
+        {
+            if (isValueReference(_dateBusinessConverter))
+            {
+                ValueBinding vb = context.getApplication().createValueBinding(_dateBusinessConverter);
+                comp.setValueBinding("dateBusinessConverter", vb);
+            }
+            else
+            {
+                try
+                {
+                    Class clazz = ClassUtils.classForName(_dateBusinessConverter);
+                    comp.setDateBusinessConverter( (DateBusinessConverter) ClassUtils.newInstance(clazz));
+                }
+                catch(ClassNotFoundException e)
+                {
+                    throw new IllegalArgumentException("Class referenced in calendarConverter not found: "+_dateBusinessConverter);
+                }
+                catch(ClassCastException e)
+                {
+                    throw new IllegalArgumentException("Class referenced in calendarConverter is not instance of org.apache.myfaces.custom.calendar.CalendarConverter: "+_dateBusinessConverter);
+                }
+            }
+        }
+    }
+}

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/date/HtmlDateRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/date/HtmlDateRenderer.java?rev=958783&r1=958782&r2=958783&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/date/HtmlDateRenderer.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/date/HtmlDateRenderer.java Mon Jun 28 23:18:57 2010
@@ -19,13 +19,12 @@
 package org.apache.myfaces.custom.date;
 
 import java.io.IOException;
-import java.io.StringReader;
 import java.text.DateFormatSymbols;
 import java.text.ParseException;
 import java.util.Calendar;
+import java.util.Date;
 import java.util.Locale;
 import java.util.Map;
-import java.util.Properties;
 import java.util.StringTokenizer;
 
 import javax.faces.application.FacesMessage;
@@ -35,16 +34,18 @@ import javax.faces.context.ResponseWrite
 import javax.faces.convert.ConverterException;
 
 import org.apache.myfaces.component.UserRoleUtils;
-import org.apache.myfaces.custom.calendar.HtmlCalendarRenderer;
+import org.apache.myfaces.custom.calendar.DateBusinessConverter;
+import org.apache.myfaces.custom.calendar.DefaultDateBusinessConverter;
 import org.apache.myfaces.custom.calendar.FunctionCallProvider;
+import org.apache.myfaces.custom.calendar.HtmlCalendarRenderer;
 import org.apache.myfaces.custom.calendar.HtmlCalendarRenderer.CalendarDateTimeConverter;
 import org.apache.myfaces.custom.date.AbstractHtmlInputDate.UserData;
-import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
 import org.apache.myfaces.shared_tomahawk.renderkit.JSFAttr;
-import org.apache.myfaces.shared_tomahawk.renderkit.html.util.JavascriptUtils;
+import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
 import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
 import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRenderer;
 import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.util.JavascriptUtils;
 import org.apache.myfaces.shared_tomahawk.util.MessageUtils;
 import org.apache.myfaces.tomahawk.util.Constants;
 
@@ -477,6 +478,16 @@ public class HtmlDateRenderer extends Ht
             inputDate.setSubmittedValue( userData );
         }
     }
+
+    private DateBusinessConverter getDateBusinessConverter(AbstractHtmlInputDate component)
+    {
+        DateBusinessConverter dateBusinessConverter = component.getDateBusinessConverter(); 
+        if (dateBusinessConverter == null)
+        {
+            dateBusinessConverter = new DefaultDateBusinessConverter();
+        }
+        return dateBusinessConverter;
+    }
     
     public Object getConvertedValue(FacesContext context, UIComponent uiComponent, Object submittedValue) throws ConverterException {
         
@@ -485,12 +496,15 @@ public class HtmlDateRenderer extends Ht
         if (inputDate.getConverter() == null)
         {
             UserData userData = (UserData) submittedValue;
+            Date date = null;
             try {
-                return userData.parse();
+                date = userData.parse();
             } catch (ParseException e) {
                 Object[] args = {uiComponent.getId()};
                 throw new ConverterException(MessageUtils.getMessage(Constants.TOMAHAWK_DEFAULT_BUNDLE, FacesMessage.SEVERITY_ERROR, DATE_MESSAGE_ID, args, context));
-            }            
+            }
+            
+            return getDateBusinessConverter(inputDate).getBusinessValue(context, inputDate, date);
         }
         else
         {

Added: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/date/HtmlInputDateTagHandler.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/date/HtmlInputDateTagHandler.java?rev=958783&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/date/HtmlInputDateTagHandler.java (added)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/date/HtmlInputDateTagHandler.java Mon Jun 28 23:18:57 2010
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.custom.date;
+
+import javax.faces.component.UIComponent;
+
+import org.apache.myfaces.custom.calendar.DateBusinessConverter;
+import org.apache.myfaces.shared_tomahawk.util.ClassUtils;
+
+import com.sun.facelets.FaceletContext;
+import com.sun.facelets.el.LegacyValueBinding;
+import com.sun.facelets.tag.MetaRule;
+import com.sun.facelets.tag.MetaRuleset;
+import com.sun.facelets.tag.Metadata;
+import com.sun.facelets.tag.MetadataTarget;
+import com.sun.facelets.tag.TagAttribute;
+import com.sun.facelets.tag.jsf.ComponentConfig;
+import com.sun.facelets.tag.jsf.html.HtmlComponentHandler;
+
+/**
+ * 
+ * @since 1.1.10
+ * @author Leonardo Uribe (latest modification by $Author: lu4242 $)
+ * @version $Revision: 691856 $ $Date: 2008-09-03 21:40:30 -0500 (mié, 03 sep 2008) $
+ */
+public class HtmlInputDateTagHandler extends HtmlComponentHandler
+{
+
+    public HtmlInputDateTagHandler(ComponentConfig config)
+    {
+        super(config);
+    }
+
+    protected MetaRuleset createMetaRuleset(Class type)
+    {
+        MetaRuleset m = super.createMetaRuleset(type);
+
+        m.addRule(DateBusinessConverterRule.INSTANCE);
+
+        return m;
+    }
+
+    public static class DateBusinessConverterRule extends MetaRule
+    {
+        public final static DateBusinessConverterRule INSTANCE = new DateBusinessConverterRule();
+
+        final static class LiteralConverterMetadata extends Metadata
+        {
+
+            private final Class dateBusinessConverterClass;
+
+            public LiteralConverterMetadata(String dateBusinessConverterClass)
+            {
+                try
+                {
+                    this.dateBusinessConverterClass = ClassUtils
+                            .classForName(dateBusinessConverterClass);
+                }
+                catch(ClassNotFoundException e)
+                {
+                    throw new IllegalArgumentException("Class referenced in calendarConverter not found: "+dateBusinessConverterClass);
+                }
+                catch(ClassCastException e)
+                {
+                    throw new IllegalArgumentException("Class referenced in calendarConverter is not instance of org.apache.myfaces.custom.calendar.CalendarConverter: "+dateBusinessConverterClass);
+                }
+            }
+
+            public void applyMetadata(FaceletContext ctx, Object instance)
+            {
+                ((AbstractHtmlInputDate) instance)
+                        .setDateBusinessConverter((DateBusinessConverter) ClassUtils
+                                .newInstance(dateBusinessConverterClass));
+            }
+        }
+
+        final static class DynamicConverterMetadata extends Metadata
+        {
+            private final TagAttribute attr;
+
+            public DynamicConverterMetadata(TagAttribute attr)
+            {
+                this.attr = attr;
+            }
+
+            public void applyMetadata(FaceletContext ctx, Object instance)
+            {
+                ((UIComponent) instance).setValueBinding("dateBusinessConverter",
+                        new LegacyValueBinding(attr.getValueExpression(ctx,
+                                DateBusinessConverter.class)));
+            }
+        }
+
+        public Metadata applyRule(String name, TagAttribute attribute,
+                MetadataTarget meta)
+        {
+            if (meta.isTargetInstanceOf(AbstractHtmlInputDate.class))
+            {
+                if ("dateBusinessConverter".equals(name)) {
+                    if (attribute.isLiteral()) {
+                        return new LiteralConverterMetadata(attribute.getValue());
+                    } else {
+                        return new DynamicConverterMetadata(attribute);
+                    }
+                }
+            }
+            return null;
+        }
+    }
+}