Cannot access inner class in bean
Asked Answered
P

1

16

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?

Prudie answered 3/4, 2012 at 16:26 Comment(0)
M
34

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

Mcgary answered 3/4, 2012 at 20:2 Comment(1)
I found this after 2 hours of looking for a bug. I guess they should at least make the exception more clear. The String here refers to the expected type(in my case it was boolean), which is really confusing.Balls

© 2022 - 2024 — McMap. All rights reserved.