You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by im...@apache.org on 2006/05/30 19:10:42 UTC

svn commit: r410321 - in /myfaces/tomahawk/trunk/sandbox: core/src/main/java/org/apache/myfaces/custom/convertNumber/ core/src/main/resources-facesconfig/META-INF/ core/src/main/tld/ core/src/main/tld/entities/ examples/src/main/java/org/apache/myfaces...

Author: imario
Date: Tue May 30 10:10:41 2006
New Revision: 410321

URL: http://svn.apache.org/viewvc?rev=410321&view=rev
Log:
convertNumber which will use either a given type or use the valueBinding to automatically determine the destination type.
To avoid references to myfaces-impl huge portions of code has been copied from its convertNumber classes

Added:
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/convertNumber/
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/convertNumber/TypedNumberConverter.java   (with props)
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/convertNumber/TypedNumberConverterTag.java   (with props)
    myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/standard_convertNumber_attributes.xml   (with props)
    myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/ui_convertNumber_attributes.xml   (with props)
    myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/NumberHolder.java   (with props)
    myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/typedNumberConvert.jsp   (with props)
Modified:
    myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml
    myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld
    myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/examples-config.xml
    myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/home.jsp

Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/convertNumber/TypedNumberConverter.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/convertNumber/TypedNumberConverter.java?rev=410321&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/convertNumber/TypedNumberConverter.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/convertNumber/TypedNumberConverter.java Tue May 30 10:10:41 2006
@@ -0,0 +1,493 @@
+package org.apache.myfaces.custom.convertNumber;
+
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
+import java.text.NumberFormat;
+import java.text.ParseException;
+import java.util.Currency;
+import java.util.Locale;
+
+import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.ConverterException;
+import javax.faces.el.ValueBinding;
+
+import org.apache.commons.beanutils.ConvertUtils;
+import org.apache.commons.beanutils.Converter;
+import org.apache.myfaces.shared_tomahawk.util.MessageUtils;
+
+/**
+ * converter which uses either the manually set <code>destType</code> or the value binding to determine the 
+ * correct destination type to convert the number to
+ *  
+ * @author imario@apache.org
+ */
+public class TypedNumberConverter implements javax.faces.convert.Converter, StateHolder
+{
+	public static final String CONVERTER_ID = "org.apache.myfaces.custom.convertNumber.TypedNumberConverter";
+
+	private Class destType;
+
+	public TypedNumberConverter()
+	{
+	}
+	
+	public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String value)
+	{
+		Object convertedValue = _getAsObject(facesContext, uiComponent, value);
+		if (convertedValue == null)
+		{
+			return null;
+		}
+
+		Class destType = getDestType(); 
+		if (destType == null)
+		{
+			ValueBinding valueBinding = uiComponent.getValueBinding("value");
+			if (valueBinding != null)
+			{
+				destType = valueBinding.getType(facesContext);
+			}
+		}
+		
+		if (destType != null)
+		{
+			Converter converter = ConvertUtils.lookup(destType);
+			if (converter == null)
+			{
+				throw new UnsupportedOperationException("cant deal with " + destType);
+			}
+
+			// setting type to null, in fact the documentation is wrong here and this type is never used
+			convertedValue = converter.convert(null, convertedValue);
+		}
+		
+		
+		return convertedValue;
+	}
+
+	public void restoreState(FacesContext facesContext, Object state)
+	{
+		Object[] states = (Object[]) state;
+		_restoreState(facesContext, states[0]);
+		destType = (Class) states[1];
+	}
+
+	public Object saveState(FacesContext facesContext)
+	{
+		return new Object[]
+		                  {
+				_saveState(facesContext),
+				destType
+		                  };
+	}
+
+	public Class getDestType()
+	{
+		return destType;
+	}
+
+	public void setDestType(Class destType)
+	{
+		this.destType = destType;
+	}
+
+	/* ORIGINAL STUFF COPIED FROM javax.faces.convert.NumberConverter */
+	
+    // internal constants
+    private static final String CONVERSION_MESSAGE_ID = "javax.faces.convert.NumberConverter.CONVERSION";
+
+
+    private static final boolean JAVA_VERSION_14;
+
+    static
+    {
+        JAVA_VERSION_14 = checkJavaVersion14();
+    }
+
+    private String _currencyCode;
+    private String _currencySymbol;
+    private Locale _locale;
+    private int _maxFractionDigits;
+    private int _maxIntegerDigits;
+    private int _minFractionDigits;
+    private int _minIntegerDigits;
+    private String _pattern;
+    private String _type = "number";
+    private boolean _groupingUsed = true;
+    private boolean _integerOnly = false;
+    private boolean _transient;
+
+    private boolean _maxFractionDigitsSet;
+    private boolean _maxIntegerDigitsSet;
+    private boolean _minFractionDigitsSet;
+    private boolean _minIntegerDigitsSet;
+
+
+    // METHODS
+    public Object _getAsObject(FacesContext facesContext, UIComponent uiComponent, String value)
+    {
+        if (facesContext == null) throw new NullPointerException("facesContext");
+        if (uiComponent == null) throw new NullPointerException("uiComponent");
+
+        if (value != null)
+        {
+            value = value.trim();
+            if (value.length() > 0)
+            {
+                NumberFormat format = getNumberFormat(facesContext);
+                format.setParseIntegerOnly(_integerOnly);
+                try
+                {
+                    return format.parse(value);
+                }
+                catch (ParseException e)
+                {
+                    throw new ConverterException(MessageUtils.getMessage(facesContext,
+                                                                               CONVERSION_MESSAGE_ID,
+                                                                               new Object[]{uiComponent.getId(),value}), e);
+                }
+            }
+        }
+        return null;
+    }
+
+    public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object value)
+    {
+        if (facesContext == null) throw new NullPointerException("facesContext");
+        if (uiComponent == null) throw new NullPointerException("uiComponent");
+
+        if (value == null)
+        {
+            return "";
+        }
+        if (value instanceof String)
+        {
+            return (String)value;
+        }
+
+        NumberFormat format = getNumberFormat(facesContext);
+        format.setGroupingUsed(_groupingUsed);
+        if (_maxFractionDigitsSet) format.setMaximumFractionDigits(_maxFractionDigits);
+        if (_maxIntegerDigitsSet) format.setMaximumIntegerDigits(_maxIntegerDigits);
+        if (_minFractionDigitsSet) format.setMinimumFractionDigits(_minFractionDigits);
+        if (_minIntegerDigitsSet) format.setMinimumIntegerDigits(_minIntegerDigits);
+        formatCurrency(format);
+        try
+        {
+            return format.format(value);
+        }
+        catch (Exception e)
+        {
+            throw new ConverterException("Cannot convert value '" + value + "'");
+        }
+    }
+
+    private NumberFormat getNumberFormat(FacesContext facesContext)
+    {
+        Locale lokale = _locale != null ? _locale : facesContext.getViewRoot().getLocale();
+
+        if (_pattern == null && _type == null)
+        {
+            throw new ConverterException("Cannot get NumberFormat, either type or pattern needed.");
+        }
+
+        // pattern
+        if (_pattern != null)
+        {
+            return new DecimalFormat(_pattern, new DecimalFormatSymbols(lokale));
+        }
+
+        // type
+        if (_type.equals("number"))
+        {
+            return NumberFormat.getNumberInstance(lokale);
+        }
+        else if (_type.equals("currency"))
+        {
+            return NumberFormat.getCurrencyInstance(lokale);
+        }
+        else if (_type.equals("percent"))
+        {
+            return NumberFormat.getPercentInstance(lokale);
+        }
+        throw new ConverterException("Cannot get NumberFormat, illegal type " + _type);
+    }
+
+    private void formatCurrency(NumberFormat format)
+    {
+        if (_currencyCode == null && _currencySymbol == null)
+        {
+            return;
+        }
+
+        boolean useCurrencyCode;
+        if (JAVA_VERSION_14)
+        {
+            useCurrencyCode = _currencyCode != null;
+        }
+        else
+        {
+            useCurrencyCode = _currencySymbol == null;
+        }
+
+        if (useCurrencyCode)
+        {
+            // set Currency
+            try
+            {
+                format.setCurrency(Currency.getInstance(_currencyCode));
+            }
+            catch (Exception e)
+            {
+                throw new ConverterException("Unable to get Currency instance for currencyCode " +
+                                             _currencyCode);
+            }
+        }
+        else if (format instanceof DecimalFormat)
+
+        {
+            DecimalFormat dFormat = (DecimalFormat)format;
+            DecimalFormatSymbols symbols = dFormat.getDecimalFormatSymbols();
+            symbols.setCurrencySymbol(_currencySymbol);
+            dFormat.setDecimalFormatSymbols(symbols);
+        }
+    }
+
+    // STATE SAVE/RESTORE
+    public void _restoreState(FacesContext facesContext, Object state)
+    {
+        Object values[] = (Object[])state;
+        _currencyCode = (String)values[0];
+        _currencySymbol = (String)values[1];
+        _locale = (Locale)values[2];
+        Integer value = (Integer)values[3];
+        _maxFractionDigits = value != null ? value.intValue() : 0;
+        value = (Integer)values[4];
+        _maxIntegerDigits = value != null ? value.intValue() : 0;
+        value = (Integer)values[5];
+        _minFractionDigits = value != null ? value.intValue() : 0;
+        value = (Integer)values[6];
+        _minIntegerDigits = value != null ? value.intValue() : 0;
+        _pattern = (String)values[7];
+        _type = (String)values[8];
+        _groupingUsed = ((Boolean)values[9]).booleanValue();
+        _integerOnly = ((Boolean)values[10]).booleanValue();
+        _maxFractionDigitsSet = ((Boolean)values[11]).booleanValue();
+        _maxIntegerDigitsSet = ((Boolean)values[12]).booleanValue();
+        _minFractionDigitsSet = ((Boolean)values[13]).booleanValue();
+        _minIntegerDigitsSet = ((Boolean)values[14]).booleanValue();
+    }
+
+    public Object _saveState(FacesContext facesContext)
+    {
+        Object values[] = new Object[15];
+        values[0] = _currencyCode;
+        values[1] = _currencySymbol;
+        values[2] = _locale;
+        values[3] = _maxFractionDigitsSet ? new Integer(_maxFractionDigits) : null;
+        values[4] = _maxIntegerDigitsSet ? new Integer(_maxIntegerDigits) : null;
+        values[5] = _minFractionDigitsSet ? new Integer(_minFractionDigits) : null;
+        values[6] = _minIntegerDigitsSet ? new Integer(_minIntegerDigits) : null;
+        values[7] = _pattern;
+        values[8] = _type;
+        values[9] = _groupingUsed ? Boolean.TRUE : Boolean.FALSE;
+        values[10] = _integerOnly ? Boolean.TRUE : Boolean.FALSE;
+        values[11] = _maxFractionDigitsSet ? Boolean.TRUE : Boolean.FALSE;
+        values[12] = _maxIntegerDigitsSet ? Boolean.TRUE : Boolean.FALSE;
+        values[13] = _minFractionDigitsSet ? Boolean.TRUE : Boolean.FALSE;
+        values[14] = _minIntegerDigitsSet ? Boolean.TRUE : Boolean.FALSE;
+        return values;
+    }
+
+    // GETTER & SETTER
+    public String getCurrencyCode()
+    {
+        return _currencyCode != null ?
+               _currencyCode :
+               getDecimalFormatSymbols().getInternationalCurrencySymbol();
+    }
+
+    public void setCurrencyCode(String currencyCode)
+    {
+        _currencyCode = currencyCode;
+    }
+
+    public String getCurrencySymbol()
+    {
+        return _currencySymbol != null ?
+               _currencySymbol :
+               getDecimalFormatSymbols().getCurrencySymbol();
+    }
+
+    public void setCurrencySymbol(String currencySymbol)
+    {
+        _currencySymbol = currencySymbol;
+    }
+
+    public boolean isGroupingUsed()
+    {
+        return _groupingUsed;
+    }
+
+    public void setGroupingUsed(boolean groupingUsed)
+    {
+        _groupingUsed = groupingUsed;
+    }
+
+    public boolean isIntegerOnly()
+    {
+        return _integerOnly;
+    }
+
+    public void setIntegerOnly(boolean integerOnly)
+    {
+        _integerOnly = integerOnly;
+    }
+
+    public Locale getLocale()
+    {
+        if (_locale != null) return _locale;
+        FacesContext context = FacesContext.getCurrentInstance();
+        return context.getViewRoot().getLocale();
+    }
+
+    public void setLocale(Locale locale)
+    {
+        _locale = locale;
+    }
+
+    public int getMaxFractionDigits()
+    {
+        return _maxFractionDigits;
+    }
+
+    public void setMaxFractionDigits(int maxFractionDigits)
+    {
+        _maxFractionDigitsSet = true;
+        _maxFractionDigits = maxFractionDigits;
+    }
+
+    public int getMaxIntegerDigits()
+    {
+        return _maxIntegerDigits;
+    }
+
+    public void setMaxIntegerDigits(int maxIntegerDigits)
+    {
+        _maxIntegerDigitsSet = true;
+        _maxIntegerDigits = maxIntegerDigits;
+    }
+
+    public int getMinFractionDigits()
+    {
+        return _minFractionDigits;
+    }
+
+    public void setMinFractionDigits(int minFractionDigits)
+    {
+        _minFractionDigitsSet = true;
+        _minFractionDigits = minFractionDigits;
+    }
+
+    public int getMinIntegerDigits()
+    {
+        return _minIntegerDigits;
+    }
+
+    public void setMinIntegerDigits(int minIntegerDigits)
+    {
+        _minIntegerDigitsSet = true;
+        _minIntegerDigits = minIntegerDigits;
+    }
+
+    public String getPattern()
+    {
+        return _pattern;
+    }
+
+    public void setPattern(String pattern)
+    {
+        _pattern = pattern;
+    }
+
+    public boolean isTransient()
+    {
+        return _transient;
+    }
+
+    public void setTransient(boolean aTransient)
+    {
+        _transient = aTransient;
+    }
+
+    public String getType()
+    {
+        return _type;
+    }
+
+    public void setType(String type)
+    {
+        //TODO: validate type
+        _type = type;
+    }
+
+    private static boolean checkJavaVersion14()
+    {
+        String version = System.getProperty("java.version");
+        if (version == null)
+        {
+            return false;
+        }
+        byte java14 = 0;
+        for (int idx = version.indexOf('.'), i = 0; idx > 0 || version != null; i++)
+        {
+            if (idx > 0)
+            {
+                byte value = Byte.parseByte(version.substring(0, 1));
+                version = version.substring(idx + 1, version.length());
+                idx = version.indexOf('.');
+                switch (i)
+                {
+                    case 0:
+                        if (value == 1)
+                        {
+                            java14 = 1;
+                            break;
+                        }
+                        else if (value > 1)
+                        {
+                            java14 = 2;
+                        }
+                    case 1:
+                        if (java14 > 0 && value >= 4)
+                        {
+                            java14 = 2;
+                        }
+                        ;
+                    default:
+                        idx = 0;
+                        version = null;
+                        break;
+                }
+            }
+            else
+            {
+                byte value = Byte.parseByte(version.substring(0, 1));
+                if (java14 > 0 && value >= 4)
+                {
+                    java14 = 2;
+                }
+                break;
+            }
+        }
+        return java14 == 2;
+    }
+
+
+    private DecimalFormatSymbols getDecimalFormatSymbols()
+    {
+        return new DecimalFormatSymbols(getLocale());
+    }
+}

Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/convertNumber/TypedNumberConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/convertNumber/TypedNumberConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/convertNumber/TypedNumberConverter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/convertNumber/TypedNumberConverterTag.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/convertNumber/TypedNumberConverterTag.java?rev=410321&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/convertNumber/TypedNumberConverterTag.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/convertNumber/TypedNumberConverterTag.java Tue May 30 10:10:41 2006
@@ -0,0 +1,369 @@
+package org.apache.myfaces.custom.convertNumber;
+
+import java.util.Locale;
+
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.el.ValueBinding;
+import javax.faces.webapp.ConverterTag;
+import javax.faces.webapp.UIComponentTag;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.PageContext;
+
+import org.apache.myfaces.shared_tomahawk.util.ClassUtils;
+import org.apache.myfaces.shared_tomahawk.util.LocaleUtils;
+
+/**
+ * converter which uses either the manually set <code>destType</code> or the
+ * value binding to determine the correct destination type to convert the number
+ * to
+ * 
+ * @author imario@apache.org
+ */
+public class TypedNumberConverterTag extends ConverterTag
+{
+	private String _destType;
+	private String _currencyCode = null;
+	private String _currencySymbol = null;
+	private String _groupingUsed = "true"; // default value as required by the
+											// spec
+	private String _integerOnly = "false"; // default value as required by the
+											// spec
+	private String _locale = null;
+	private String _maxFractionDigits = null;
+	private String _maxIntegerDigits = null;
+	private String _minFractionDigits = null;
+	private String _minIntegerDigits = null;
+	private String _pattern = null;
+	private String _type = "number"; // default value as required by the spec
+
+	public TypedNumberConverterTag()
+	{
+		setConverterId(TypedNumberConverter.CONVERTER_ID);
+	}
+
+	public void setDestType(String destType)
+	{
+		_destType = destType;
+	}
+
+	public void setCurrencyCode(String currencyCode)
+	{
+		_currencyCode = currencyCode;
+	}
+
+	public void setCurrencySymbol(String currencySymbol)
+	{
+		_currencySymbol = currencySymbol;
+	}
+
+	public void setGroupingUsed(String groupingUsed)
+	{
+		_groupingUsed = groupingUsed;
+	}
+
+	public void setIntegerOnly(String integerOnly)
+	{
+		_integerOnly = integerOnly;
+	}
+
+	public void setLocale(String locale)
+	{
+		_locale = locale;
+	}
+
+	public void setMaxFractionDigits(String maxFractionDigits)
+	{
+		_maxFractionDigits = maxFractionDigits;
+	}
+
+	public void setMaxIntegerDigits(String maxIntegerDigits)
+	{
+		_maxIntegerDigits = maxIntegerDigits;
+	}
+
+	public void setMinFractionDigits(String minFractionDigits)
+	{
+		_minFractionDigits = minFractionDigits;
+	}
+
+	public void setMinIntegerDigits(String minIntegerDigits)
+	{
+		_minIntegerDigits = minIntegerDigits;
+	}
+
+	public void setPattern(String pattern)
+	{
+		_pattern = pattern;
+	}
+
+	public void setType(String type)
+	{
+		_type = type;
+	}
+
+	public void setPageContext(PageContext context)
+	{
+		super.setPageContext(context);
+		setConverterId(TypedNumberConverter.CONVERTER_ID);
+	}
+
+	protected Converter createConverter() throws JspException
+	{
+		TypedNumberConverter converter = (TypedNumberConverter) super.createConverter();
+
+		FacesContext facesContext = FacesContext.getCurrentInstance();
+		setConverterCurrencyCode(facesContext, converter, _currencyCode);
+		setConverterCurrencySymbol(facesContext, converter, _currencySymbol);
+		setConverterGroupingUsed(facesContext, converter, _groupingUsed);
+		setConverterIntegerOnly(facesContext, converter, _integerOnly);
+		setConverterLocale(facesContext, converter, _locale);
+		setConverterMaxFractionDigits(
+			facesContext, converter, _maxFractionDigits);
+		setConverterMaxIntegerDigits(facesContext, converter, _maxIntegerDigits);
+		setConverterMinFractionDigits(
+			facesContext, converter, _minFractionDigits);
+		setConverterMinIntegerDigits(facesContext, converter, _minIntegerDigits);
+		setConverterPattern(facesContext, converter, _pattern);
+		setConverterType(facesContext, converter, _type);
+		setDestType(facesContext, converter, _destType);
+
+		return converter;
+	}
+
+	protected static void setConverterLocale(FacesContext facesContext,
+			TypedNumberConverter converter, String value)
+	{
+		if (value == null)
+			return;
+		if (UIComponentTag.isValueReference(value))
+		{
+			ValueBinding vb = facesContext.getApplication().createValueBinding(
+				value);
+			converter.setLocale((Locale) vb.getValue(facesContext));
+		}
+		else
+		{
+			Locale locale = LocaleUtils.converterTagLocaleFromString(value);
+			converter.setLocale(locale);
+		}
+	}
+
+	private static void setConverterCurrencyCode(FacesContext facesContext,
+			TypedNumberConverter converter, String value)
+	{
+		if (value == null)
+			return;
+		if (UIComponentTag.isValueReference(value))
+		{
+			ValueBinding vb = facesContext.getApplication().createValueBinding(
+				value);
+			converter.setCurrencyCode((String) vb.getValue(facesContext));
+		}
+		else
+		{
+			converter.setCurrencyCode(value);
+		}
+	}
+
+	private static void setConverterCurrencySymbol(FacesContext facesContext,
+			TypedNumberConverter converter, String value)
+	{
+		if (value == null)
+			return;
+		if (UIComponentTag.isValueReference(value))
+		{
+			ValueBinding vb = facesContext.getApplication().createValueBinding(
+				value);
+			converter.setCurrencySymbol((String) vb.getValue(facesContext));
+		}
+		else
+		{
+			converter.setCurrencySymbol(value);
+		}
+	}
+
+	private static void setConverterGroupingUsed(FacesContext facesContext,
+			TypedNumberConverter converter, String value)
+	{
+		if (value == null)
+			return;
+		if (UIComponentTag.isValueReference(value))
+		{
+			ValueBinding vb = facesContext.getApplication().createValueBinding(
+				value);
+			Boolean b = (Boolean) vb.getValue(facesContext);
+			if (b != null)
+			{
+				converter.setGroupingUsed(b.booleanValue());
+			}
+		}
+		else
+		{
+			converter.setGroupingUsed(Boolean.valueOf(value).booleanValue());
+		}
+	}
+
+	private static void setConverterIntegerOnly(FacesContext facesContext,
+			TypedNumberConverter converter, String value)
+	{
+		if (value == null)
+			return;
+		if (UIComponentTag.isValueReference(value))
+		{
+			ValueBinding vb = facesContext.getApplication().createValueBinding(
+				value);
+			Boolean b = (Boolean) vb.getValue(facesContext);
+			if (b != null)
+			{
+				converter.setIntegerOnly(b.booleanValue());
+			}
+		}
+		else
+		{
+			converter.setIntegerOnly(Boolean.valueOf(value).booleanValue());
+		}
+	}
+
+	private static void setConverterMaxFractionDigits(
+			FacesContext facesContext, TypedNumberConverter converter, String value)
+	{
+		if (value == null)
+			return;
+		if (UIComponentTag.isValueReference(value))
+		{
+			ValueBinding vb = facesContext.getApplication().createValueBinding(
+				value);
+			Integer i = (Integer) vb.getValue(facesContext);
+			if (i != null)
+			{
+				converter.setMaxFractionDigits(i.intValue());
+			}
+		}
+		else
+		{
+			converter.setMaxFractionDigits(Integer.parseInt(value));
+		}
+	}
+
+	private static void setConverterMaxIntegerDigits(FacesContext facesContext,
+			TypedNumberConverter converter, String value)
+	{
+		if (value == null)
+			return;
+		if (UIComponentTag.isValueReference(value))
+		{
+			ValueBinding vb = facesContext.getApplication().createValueBinding(
+				value);
+			Integer i = (Integer) vb.getValue(facesContext);
+			if (i != null)
+			{
+				converter.setMaxIntegerDigits(i.intValue());
+			}
+		}
+		else
+		{
+			converter.setMaxIntegerDigits(Integer.parseInt(value));
+		}
+	}
+
+	private static void setConverterMinFractionDigits(
+			FacesContext facesContext, TypedNumberConverter converter, String value)
+	{
+		if (value == null)
+			return;
+		if (UIComponentTag.isValueReference(value))
+		{
+			ValueBinding vb = facesContext.getApplication().createValueBinding(
+				value);
+			Integer i = (Integer) vb.getValue(facesContext);
+			if (i != null)
+			{
+				converter.setMinFractionDigits(i.intValue());
+			}
+		}
+		else
+		{
+			converter.setMinFractionDigits(Integer.parseInt(value));
+		}
+	}
+
+	private static void setConverterMinIntegerDigits(FacesContext facesContext,
+			TypedNumberConverter converter, String value)
+	{
+		if (value == null)
+			return;
+		if (UIComponentTag.isValueReference(value))
+		{
+			ValueBinding vb = facesContext.getApplication().createValueBinding(
+				value);
+			Integer i = (Integer) vb.getValue(facesContext);
+			if (i != null)
+			{
+				converter.setMinIntegerDigits(i.intValue());
+			}
+		}
+		else
+		{
+			converter.setMinIntegerDigits(Integer.parseInt(value));
+		}
+	}
+
+	private static void setConverterPattern(FacesContext facesContext,
+			TypedNumberConverter converter, String value)
+	{
+		if (value == null)
+			return;
+		if (UIComponentTag.isValueReference(value))
+		{
+			ValueBinding vb = facesContext.getApplication().createValueBinding(
+				value);
+			converter.setPattern((String) vb.getValue(facesContext));
+		}
+		else
+		{
+			converter.setPattern(value);
+		}
+	}
+
+	private static void setConverterType(FacesContext facesContext,
+			TypedNumberConverter converter, String value)
+	{
+		if (value == null)
+			return;
+		if (UIComponentTag.isValueReference(value))
+		{
+			ValueBinding vb = facesContext.getApplication().createValueBinding(
+				value);
+			converter.setType((String) vb.getValue(facesContext));
+		}
+		else
+		{
+			converter.setType(value);
+		}
+	}
+
+	private static void setDestType(FacesContext facesContext,
+			TypedNumberConverter converter, String value) throws JspException
+	{
+		if (value == null)
+			return;
+		if (UIComponentTag.isValueReference(value))
+		{
+			ValueBinding vb = facesContext.getApplication().createValueBinding(
+				value);
+			converter.setDestType((Class) vb.getValue(facesContext));
+		}
+		else
+		{
+			try
+			{
+				converter.setDestType(ClassUtils.classForName(value));
+			}
+			catch (ClassNotFoundException e)
+			{
+				throw new JspException(e);
+			}
+		}
+	}
+}

Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/convertNumber/TypedNumberConverterTag.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/convertNumber/TypedNumberConverterTag.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/convertNumber/TypedNumberConverterTag.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml?rev=410321&r1=410320&r2=410321&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml Tue May 30 10:10:41 2006
@@ -196,6 +196,10 @@
      <converter-class>org.apache.myfaces.custom.convertDateTime.DateTimeConverter</converter-class>
   </converter>
 
+  <converter>
+     <converter-id>org.apache.myfaces.custom.convertNumber.TypedNumberConverter</converter-id>
+     <converter-class>org.apache.myfaces.custom.convertNumber.TypedNumberConverter</converter-class>
+  </converter>
 
   <!-- sandbox managed beans -->
   <managed-bean>

Added: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/standard_convertNumber_attributes.xml
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/standard_convertNumber_attributes.xml?rev=410321&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/standard_convertNumber_attributes.xml (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/standard_convertNumber_attributes.xml Tue May 30 10:10:41 2006
@@ -0,0 +1,75 @@
+<attribute>
+    <name>currencyCode</name>
+    <required>false</required>
+    <rtexprvalue>false</rtexprvalue>
+    <description>ISO 4217 currency code</description>
+</attribute>
+<attribute>
+    <name>currencySymbol</name>
+    <required>false</required>
+    <rtexprvalue>false</rtexprvalue>
+    <description>
+        The currency symbol used to format a currency value.  Defaults
+        to the currency symbol for locale.
+    </description>
+</attribute>
+<attribute>
+    <name>groupingUsed</name>
+    <required>false</required>
+    <rtexprvalue>false</rtexprvalue>
+    <description>Specifies whether output will contain grouping separators.  Default: true.</description>
+</attribute>
+<attribute>
+    <name>integerOnly</name>
+    <required>false</required>
+    <rtexprvalue>false</rtexprvalue>
+    <description>Specifies whether only the integer part of the input will be parsed.  Default: false.</description>
+</attribute>
+<attribute>
+    <name>locale</name>
+    <required>false</required>
+    <rtexprvalue>false</rtexprvalue>
+    <description>
+        The name of the locale to be used, instead of the default as
+        specified in the faces configuration file.
+    </description>
+</attribute>
+<attribute>
+    <name>maxFractionDigits</name>
+    <required>false</required>
+    <rtexprvalue>false</rtexprvalue>
+    <description>The maximum number of digits in the fractional portion of the number.</description>
+</attribute>
+<attribute>
+    <name>maxIntegerDigits</name>
+    <required>false</required>
+    <rtexprvalue>false</rtexprvalue>
+    <description>The maximum number of digits in the integer portion of the number.</description>
+</attribute>
+<attribute>
+    <name>minFractionDigits</name>
+    <required>false</required>
+    <rtexprvalue>false</rtexprvalue>
+    <description>The minimum number of digits in the fractional portion of the number.</description>
+</attribute>
+<attribute>
+    <name>minIntegerDigits</name>
+    <required>false</required>
+    <rtexprvalue>false</rtexprvalue>
+    <description>The minimum number of digits in the integer portion of the number.</description>
+</attribute>
+<attribute>
+    <name>pattern</name>
+    <required>false</required>
+    <rtexprvalue>false</rtexprvalue>
+    <description>A custom Date formatting pattern, in the format used by java.text.SimpleDateFormat.</description>
+</attribute>
+<attribute>
+    <name>type</name>
+    <required>false</required>
+    <rtexprvalue>false</rtexprvalue>
+    <description>
+        The type of formatting/parsing to be performed.  Values include:
+        number, currency, and percentage.  Default: number.
+    </description>
+</attribute>

Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/standard_convertNumber_attributes.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/standard_convertNumber_attributes.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/standard_convertNumber_attributes.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/ui_convertNumber_attributes.xml
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/ui_convertNumber_attributes.xml?rev=410321&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/ui_convertNumber_attributes.xml (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/ui_convertNumber_attributes.xml Tue May 30 10:10:41 2006
@@ -0,0 +1,6 @@
+<attribute>
+    <name>destType</name>
+    <required>false</required>
+    <rtexprvalue>false</rtexprvalue>
+    <description>The java class name the value should be converted to. Default: automatically determined through valueBinding</description>
+</attribute>

Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/ui_convertNumber_attributes.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/ui_convertNumber_attributes.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/ui_convertNumber_attributes.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld?rev=410321&r1=410320&r2=410321&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld Tue May 30 10:10:41 2006
@@ -130,6 +130,8 @@
 <!ENTITY standard_conversation_attributes	SYSTEM "entities/standard_conversation_attributes.xml">
 <!ENTITY conversation_attributes	SYSTEM "entities/conversation_attributes.xml">
 <!ENTITY ext_escape_attribute	SYSTEM "entities-share/ext_escape_attribute.xml">
+<!ENTITY convertNumber_attributes SYSTEM "entities/standard_convertNumber_attributes.xml">
+<!ENTITY ui_convertNumber_attributes SYSTEM "entities/ui_convertNumber_attributes.xml">
 ]>
 
 <taglib>
@@ -1116,5 +1118,23 @@
 
 		&standard_conversation_attributes;
 		&conversation_attributes;
+	</tag>
+
+	<tag>
+		<name>convertNumber</name>
+		<tag-class>org.apache.myfaces.custom.convertNumber.TypedNumberConverterTag</tag-class>
+		<body-content>JSP</body-content>
+		<description>
+            This tag creates a number formatting converter and associates it
+            with the nearest parent UIComponent.
+            
+			It uses either the manually set &lt;code&gt;destType&lt;/code&gt; or the value binding
+			to determine the correct destination type to convert the number to.
+ 
+            Unless otherwise specified, all attributes accept static values or EL expressions.
+		</description>
+		&convertNumber_attributes;
+		&ui_convertNumber_attributes;
+		
 	</tag>
 </taglib>

Added: myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/NumberHolder.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/NumberHolder.java?rev=410321&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/NumberHolder.java (added)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/NumberHolder.java Tue May 30 10:10:41 2006
@@ -0,0 +1,62 @@
+package org.apache.myfaces.examples;
+
+import java.math.BigDecimal;
+
+public class NumberHolder
+{
+	private short shortNumber;
+	private int intNumber;
+	private long longNumber;
+	private double doubleNumber;
+	private BigDecimal bigDecimalNumber;
+	private double doubleNumberManual;
+	
+	public BigDecimal getBigDecimalNumber()
+	{
+		return bigDecimalNumber;
+	}
+	public void setBigDecimalNumber(BigDecimal bigDecimalNumber)
+	{
+		this.bigDecimalNumber = bigDecimalNumber;
+	}
+	public double getDoubleNumber()
+	{
+		return doubleNumber;
+	}
+	public void setDoubleNumber(double doubleNumber)
+	{
+		this.doubleNumber = doubleNumber;
+	}
+	public int getIntNumber()
+	{
+		return intNumber;
+	}
+	public void setIntNumber(int intNumber)
+	{
+		this.intNumber = intNumber;
+	}
+	public long getLongNumber()
+	{
+		return longNumber;
+	}
+	public void setLongNumber(long longNumber)
+	{
+		this.longNumber = longNumber;
+	}
+	public short getShortNumber()
+	{
+		return shortNumber;
+	}
+	public void setShortNumber(short shortNumber)
+	{
+		this.shortNumber = shortNumber;
+	}
+	public double getDoubleNumberManual()
+	{
+		return doubleNumberManual;
+	}
+	public void setDoubleNumberManual(double doubleNumberManual)
+	{
+		this.doubleNumberManual = doubleNumberManual;
+	}
+}

Propchange: myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/NumberHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/NumberHolder.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/NumberHolder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/examples-config.xml
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/examples-config.xml?rev=410321&r1=410320&r2=410321&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/examples-config.xml (original)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/examples-config.xml Tue May 30 10:10:41 2006
@@ -434,7 +434,12 @@
 		<managed-bean-scope>request</managed-bean-scope>
 	</managed-bean>
 	
-
+    <managed-bean>
+    	<managed-bean-name>numberHolder</managed-bean-name>
+    	<managed-bean-class>org.apache.myfaces.examples.NumberHolder</managed-bean-class>
+    	<managed-bean-scope>request</managed-bean-scope>
+    </managed-bean>
+    
     <!-- navigation rules -->
     <navigation-rule>
 		<navigation-case>

Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/home.jsp
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/home.jsp?rev=410321&r1=410320&r2=410321&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/home.jsp (original)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/home.jsp Tue May 30 10:10:41 2006
@@ -84,7 +84,9 @@
 	 			<h:commandLink action="go_scope_shop"><f:verbatim>Scopeshop1, an extended saveState Example showing a wizard</f:verbatim></h:commandLink>
            		<h:outputLink value="effect.jsf" ><f:verbatim>Effect - DOJO and script.aculo.us effects</f:verbatim></h:outputLink>
 	            <h:outputLink value="dojo/textareatestjsfonly.jsf"><f:verbatim>Integration of Dojo Toolkit</f:verbatim></h:outputLink>
-                <h:outputLink value="killSession.jsf"><f:verbatim>Kill Session - refreshes state</f:verbatim></h:outputLink>
+                <h:outputLink value="killSession.jsf"><f:verbatim>Kill Session - refreshes state</f:verbatim></h:outputLink>
+                <h:outputLink value="typedNumberConvert.jsf"><f:verbatim>automatically convert the number to the correct type</f:verbatim></h:outputLink>
+                
             </h:panelGrid>
             <h:panelGrid style="padding-left:25px">
                 <h:outputLink value="ajaxChildComboBox.jsf" >

Added: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/typedNumberConvert.jsp
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/typedNumberConvert.jsp?rev=410321&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/typedNumberConvert.jsp (added)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/typedNumberConvert.jsp Tue May 30 10:10:41 2006
@@ -0,0 +1,104 @@
+<%@ page session="false" contentType="text/html;charset=utf-8"%>
+<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
+<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
+<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
+<%@ taglib uri="http://myfaces.apache.org/sandbox" prefix="s"%>
+
+<html>
+
+<%@include file="inc/head.inc" %>
+
+<!--
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+//-->
+
+<body>
+
+<!--
+managed beans used:
+    validateForm
+-->
+
+<f:view>
+
+    <f:loadBundle basename="org.apache.myfaces.examples.resource.example_messages" var="example_messages"/>
+
+    <h:panelGroup id="body">
+
+	<f:verbatim>Enter numbers with or without fraction and see how we convert them to the type required for bean</f:verbatim>
+	
+	<h:form id="form1">
+		<h:panelGrid columns="4">
+		
+			<h:outputLabel for="shortNumber" value="Enter Number (autoconvert to short)" />
+			<h:inputText id="shortNumber" value="#{numberHolder.shortNumber}">
+				<s:convertNumber />
+			</h:inputText>
+			<h:outputText value="current value: #{numberHolder.shortNumber}" />
+			<t:message for="shortNumber" styleClass="error" />
+			
+			<h:outputLabel for="intNumber" value="Enter Number (autoconvert to int)" />
+			<h:inputText id="intNumber" value="#{numberHolder.intNumber}">
+				<s:convertNumber />
+			</h:inputText>
+			<h:outputText value="current value: #{numberHolder.intNumber}" />
+			<t:message for="intNumber" styleClass="error" />
+
+			<h:outputLabel for="longNumber" value="Enter Number (autoconvert to long)" />
+			<h:inputText id="longNumber" value="#{numberHolder.longNumber}">
+				<s:convertNumber />
+			</h:inputText>
+			<h:outputText value="current value: #{numberHolder.longNumber}" />
+			<t:message for="longNumber" styleClass="error" />
+
+			<h:outputLabel for="doubleNumber" value="Enter Number (autoconvert to double)" />
+			<h:inputText id="doubleNumber" value="#{numberHolder.doubleNumber}">
+				<s:convertNumber />
+			</h:inputText>
+			<h:outputText value="current value: #{numberHolder.doubleNumber}" />
+			<t:message for="doubleNumber" styleClass="error" />
+			
+			<h:outputLabel for="bigDecimalNumber" value="Enter Number (autoconvert to bigDecimal)" />
+			<h:inputText id="bigDecimalNumber" value="#{numberHolder.bigDecimalNumber}">
+				<s:convertNumber />
+			</h:inputText>
+			<h:outputText value="current value: #{numberHolder.bigDecimalNumber}" />
+			<t:message for="bigDecimalNumber" styleClass="error" />
+
+			<h:outputLabel for="doubleNumberManual" value="Enter Number (convert to double using destType attribute)" />
+			<h:inputText id="doubleNumberManual" value="#{numberHolder.doubleNumberManual}">
+				<s:convertNumber destType="java.lang.Double" />
+			</h:inputText>
+			<h:outputText value="current value: #{numberHolder.doubleNumberManual}" />
+			<t:message for="doubleNumberManual" styleClass="error" />
+			
+			<h:panelGroup/>
+				<h:commandButton />
+			<h:panelGroup/>
+		
+		</h:panelGrid>
+	</h:form>
+
+    </h:panelGroup>
+
+</f:view>
+
+<%@include file="inc/page_footer.jsp" %>
+
+</body>
+
+</html>

Propchange: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/typedNumberConvert.jsp
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/typedNumberConvert.jsp
------------------------------------------------------------------------------
    svn:mime-type = text/plain