Search code examples
javajsf-2el

EL getType obj.property1.sub_property


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}


Solution

  • 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...