سؤال

I want to get the type of the sub property of the Object "obj", which is accessible as

obj.property1.sub_property

this code works only for direct property like obj.property

FacesContext.getCurrentInstance().getApplication().
     getELResolver().getType(FacesContext.getCurrentInstance().getELContext(),
     obj, "property1");

but how to make this work

FacesContext.getCurrentInstance().getApplication().
     getELResolver().getType(FacesContext.getCurrentInstance().getELContext(),
     obj, "property1.sub_property");

or How to get the TYPE of the complete expression #{obj.property1.sub_property}

هل كانت مفيدة؟

المحلول 2

this work only if obj.preperty1 is not null unless we have a null pointer exception

new ExpressionFactoryImpl().createValueExpression(
     FacesUtils.getFacesContext().getELContext(),
     expr, Object.class).getType(
     FacesUtils.getFacesContext().getELContext())

because as kolossus mention it will evaluate the first part, then the second...

نصائح أخرى

That's the way ELResolver works. Even under the covers, each member is evaluated separately.

From the the specification:

The ELResolver concept is the heart of the unified EL...For example, in rendering the component behind the tag <h:outputText value=#{user.address.street}/>, the ELResolver is called three times. Once to resolve user, again to resolve the address property of user and finally,to resolve the street property of address

Translation: You need to evaluate property1 and subproperty separately. I'm typing this on a phone so I'll add a code sample later

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top