webtier@glassfish.java.net

Re: How to use custom ExpressionFactory? - glassfish classloader problems

From: <webtier_at_javadesktop.org>
Date: Fri, 01 May 2009 10:10:18 PDT

That IAE is caught, thus no stacktrace:

This is from UISelectOne source from jsf1.2_04
[code]
                //Coerce the item value type before comparing values.
                Class type = value.getClass();
                Object newValue;
                try {
                    newValue = getFacesContext().getApplication().
                        getExpressionFactory().coerceToType(item.getValue(), type);
                } catch (Exception e) {
                    // this should catch an ELException, but there is a bug
                    // in ExpressionFactory.coerceToType() in GF
                    newValue = null;
                }
[/code]

This is from com.sun.el.ExpressionFactory:
[code]
public Object coerceToType(Object obj, Class type) {
    return ELSupport.coerceToType(obj, type);
}
[/code]

And this is from ELSupport
[code]
    public final static Object coerceToType(final Object obj, final Class type)
            throws IllegalArgumentException {
        if (type == null || Object.class.equals(type)) {
            return obj;
        }
        if (String.class.equals(type)) {
            return coerceToString(obj);
        }
        if (ELArithmetic.isNumberType(type)) {
            return coerceToNumber(obj, type);
        }
        if (Character.class.equals(type) || Character.TYPE == type) {
            return coerceToCharacter(obj);
        }
        if (Boolean.class.equals(type) || Boolean.TYPE == type) {
            return coerceToBoolean(obj);
        }
        if (type.isEnum()) {
            return coerceToEnum(obj, type);
        }
        if (obj != null && type.isAssignableFrom(obj.getClass())) {
            return obj;
        }

        // new to spec
        if (obj == null)
            return null;
        if (obj instanceof String) {
            if ("".equals(obj))
                return null;
            PropertyEditor editor = PropertyEditorManager.findEditor(type);
            if (editor != null) {
                editor.setAsText((String) obj);
                return editor.getValue();
            }
        }
        throw new IllegalArgumentException(MessageFactory.get("error.convert",
                obj, obj.getClass(), type));
    }

[/code]


So if item.getValue() is of type MyClass, but type is of class MyClass$$EnhancerByCGLib$3453453453 which is a subclass of MyClass, this results in newValue being set to null.
This is because type.isAssignableFrom(obj.getClass()) return false, which is is correct behaviour. But I want hibernate proxy objects being handled as if they were real objects so I implemented a custom Expressionfactory which checks first if this situation exists and passes everything else to the standard implementation.
This custom ExpressionFactory is working ok, but i don't want to put it into glassfish's lib folder. Instead I want to deploy it within the webapp, but there it won't be picked up by the classloader that is used while starting the jsf implementation.
[Message sent by forum member 'cmdrk' (cmdrk)]

http://forums.java.net/jive/thread.jspa?messageID=344669