Search code examples
jsf-2elinner-classesmanaged-bean

Cannot access inner class in bean


I'm using JSF 2.0. I have a managed bean which I can access through my xhtml page. Inside the bean I declared an inner class. I can access ArrayList<String> of managed bean but not ArrayList<InnerClass> and I get the error that the InnerClass does not have a readable property. Anyone know what's wrong?


Solution

  • That can happen if the inner class is not public. It will then be invisible to other classes outside the package (like as JSF/EL itself!). Make sure that the inner class is public whenever you need to access it by JSF/EL.

    public class Bean {
    
        public class InnerClass {
            // ...
        }
    
    }
    

    Otherwise it will be interpreted as String and you'll get confusing exceptions like

    javax.el.ELException: /test.xhtml: Property 'someProperty' not readable on type java.lang.String

    when you want to access #{innerClass.someProperty}.