Hi,

When i have this _expression_:

student.address.country.code

then if anything like address or country is null Ognl will throw this exception:

Caused by: ognl.OgnlException: source is null for getProperty(null, "code")
    at ognl.OgnlRuntime.getProperty(OgnlRuntime.java:1611)
    at ognl.ASTProperty.getValueBody(ASTProperty.java:96)

i find this completely stupid. And i can't find a way for ognl to just see this, that a parent == null
and then just return directly null instead of going to try to get the next property on a null.

The drawback is for example that you have to place everywhere dummy objects if the student
doesn't have an address filled in just yet.

They have some support for those NullHandlers but then you do the same thing creating dummy objects
for everything and if i then ask for:

student.address.country

i would get a Country object (that is completely empty) instead of just wat it is a null.
So in my eyes this is also not the thing to do.

Of course if you are in an edit page. You have to create all those dummies because the values have to be able
to submit it into there models. But if it is just for displaying data this is quite annoying.

Does anybody has a good idea to fix this i can think of one but i am not really happy with that:

            try
            {
                // note: if property type is null it is ignored by Ognl
                prepareContext(component);
                return Ognl.getValue(_expression_, conversionContext, modelObject,
                        propertyType(component));
            }
            catch (OgnlException e)
            {
                if(e.getMessage().indexOf("source is null for getProperty"))
                {
                    return null;
                }
                throw new WicketRuntimeException("OGNL Exception: _expression_='" + _expression_ + "'; path='" + component.getPath() + "'", e);
            }

so testing for the message and then just return null (silently)

johan

Reply via email to