JSF 2 - @ManagedBean not detected

前端 未结 2 1063
广开言路
广开言路 2020-12-11 05:31

I have a ParentBean class which has the @ManagedBean annotation. If I subclass this class, the ChildBean does not inherit the @ManagedBean annotati

2条回答
  •  半阙折子戏
    2020-12-11 05:43

    javax.annotation.ManagedBean does not have @Inherited. javax.faces.ManagedBean has. Check your imports.

    Furthermore, I wouldn't rely on that. I don't see it defined in the spec, but usually inheritance with jsf managed bean is a bad idea. Even if you have it, you should have an abstract base class that holds common functionality but is not a managed bean by itself.

    Another thing - reading the code later on would be harder if you don't have the annotation on the bean. It may take a while until the reader realizes it is inherited.

    So put @ManagedBean on each bean, and don't overuse inheritance.

提交回复
热议问题