[EMAIL PROTECTED] schrieb:
> -            valueType = expression.getType(facesContext.getELContext());
> +            //By some strange reason vb.getType(facesContext.getELContext());
> +            //does not return the same as 
> vb.getValue(facesContext.getELContext()).getClass(),
> +            //so we need to use this instead.
> +            Object value = expression.getValue(facesContext.getELContext()); 
> +            valueType = (value != null) ? value.getClass() :
> +                expression.getType(facesContext.getELContext()) ;
> +            
>              if (valueType != null && valueType.isArray())
>              {
>                  arrayComponentType = valueType.getComponentType();
>   

The behaviour of vb.getType doesn't seem so strange.

The ValueExpression.getType method returns the *declared* type of a
property.  Specifically, the javadocs say that it is the type you would
pass to the property setter. If a method is "public Foo getFoo()", then
getType is "Foo". This result is always the same over a run of the
application, so can be cached.

Checking the concrete type of the object returned from the getter is
quite different; it may be null, or a subtype of Foo.  And for code that
doesn't use generics, "foo['key']" only statically implies a type of
Object, which is the problem here, yes? Presumably declaring the map on
the backing bean as Map<String, List<Boolean>> would also resolve the
issue, as ValueExpression.getType would then return List<Boolean> as the
type, rather than Object.

I agree that in this case we want to check the runtime type rather than
the static type. Maybe we should check the code for other cases where
ValueExpression.getType is being called...

Regards, Simon

Reply via email to