Why can't I have static public fields in my managed beans?

Posted by AlanObject on Stack Overflow See other posts from Stack Overflow or by AlanObject
Published on 2011-11-26T01:05:21Z Indexed on 2011/11/26 1:50 UTC
Read the original article Hit count: 193

Filed under:
|
|
|

I just started using the Netbeans 7.1 beta and it is calling out errors of a type which I have never seen before. Specifically:

A managed bean with a public field should not declare any scope other than @Dependent.

The fields it is complaining about are public static final. I can understand the restriction on non-static fields, but I can't think of a good reason this would not be allowed for a static field. Unfortunately I use a lot of them since I don't like having constants in my code.

I note that even though I get the red dot in the margin in the editor, the maven-driven build still works and GlassFish still runs my application the way I would expect.

So what is my denoument on this issue? Am I going to have to move my static fields elsewhere or is there another way of handling this?

© Stack Overflow or respective owner

Related posts about netbeans

Related posts about jsf-2.0