javajsfelpropertynotfoundexception

EL throws PropertyNotFoundException when method is static


Given the following JSF code:
<h:outputText value="#{bean.foo}" />
and proper method in my bean:
public String getFoo(){ return "foo"; }
everything works just great. But when I switch my bean's method to static
public static String getFoo(){ return "foo"; }
It does not work anymore, because EL throws an exception:

javax.el.PropertyNotFoundException: The class 'bean' does not have the property 'foo'.

Why does the method must not be static?


Solution

  • By making foo static it no longer fits into the definition of a property of this class. You can still call getFoo() directly, but it won't autowire this for you when constructed the way you've changed it