small change,

since expression .getType() can be java.lang.Object (like
#{currentRow.theValue}),
but the actual value of the expression can still be a number.


  private boolean _isNumericField(
    FacesBean bean
    )
  {
    ValueExpression expression = getValueExpression(bean);
    if (expression != null)
    {
      boolean isNumberic = false;
      FacesContext context = FacesContext.getCurrentInstance();
      Class type = expression.getType(context.getELContext());

      isNumberic = _checkNumber(type);

      //we might see java.lang.Object here, like #{row.value},
      //so let's check if the value is a number
      if(!isNumberic)
      {
        Object value = expression.getValue(context.getELContext());
        if(value != null)
          isNumberic = _checkNumber(value.getClass());
      }
      return isNumberic;
    }
    return false;
  }

  private boolean _checkNumber(
    Class clazz)
  {
    return Number.class.isAssignableFrom(clazz) ||
(clazz.isPrimitive() && _NUMBER_TYPES.contains(clazz));
  }



On 8/14/07, Matthias Wessendorf <[EMAIL PROTECTED]> wrote:
> Hi,
>
> there is a private _isNumericField() method inside the renderer. Not called 
> atm.
> Wouldn't it be nice, if we render a CSS rule (text-align: right;),
> when the rendered input field is a numberic field ?
>
> For that, we could do something like:
>
>   private boolean _isNumericField(
>     FacesBean bean
>     )
>   {
>     ValueExpression binding = getValueExpression(bean);
>     if (binding != null)
>     {
>       FacesContext context = FacesContext.getCurrentInstance();
>       Class type = binding.getType(context.getELContext());
>       return Number.class.isAssignableFrom(type) ||
> (type.isPrimitive() && _NUMBER_TYPES.contains(type));
>     }
>     return false;
>   }
>
>
> Where _NUMBER_TYPES is:
>   private final static Set<Class> _NUMBER_TYPES = new HashSet<Class>();
>
>   static
>   {
>     _NUMBER_TYPES.add(Byte.TYPE);
>     _NUMBER_TYPES.add(Short.TYPE);
>     _NUMBER_TYPES.add(Integer.TYPE);
>     _NUMBER_TYPES.add(Long.TYPE);
>     _NUMBER_TYPES.add(Float.TYPE);
>     _NUMBER_TYPES.add(Double.TYPE);
>   }
>
> by making it protected, subclasses could also use it..
>
> What do you think ?
>
> (yes, I used unified EL in this example..., on trunk that would be
> ValueBinding for instance)
>
> -Matthias
>
> --
> Matthias Wessendorf
>
> further stuff:
> blog: http://matthiaswessendorf.wordpress.com/
> mail: matzew-at-apache-dot-org
>


-- 
Matthias Wessendorf

further stuff:
blog: http://matthiaswessendorf.wordpress.com/
mail: matzew-at-apache-dot-org

Reply via email to