Getter在默认方法JSF的接口中

Fel*_*oli 6 jsf el java-8 default-method propertynotfoundexception

我有一个具有以下默认方法的接口:

default Integer getCurrentYear() {return DateUtil.getYear();}
Run Code Online (Sandbox Code Playgroud)

我还有一个实现此接口的控制器,但它不会覆盖该方法.

public class NotifyController implements INotifyController
Run Code Online (Sandbox Code Playgroud)

我试图从我的xhtml访问此方法,如下所示:

#{notifyController.currentYear}
Run Code Online (Sandbox Code Playgroud)

但是,当我打开屏幕时,会出现以下错误:

The class 'br.com.viasoft.controller.notify.notifyController' does not have the property 'anoAtual'
Run Code Online (Sandbox Code Playgroud)

如果我从我的控制器的实例访问此方法,它返回正确的值,但是当我尝试从我的xhtml访问它作为"属性"时,它会发生此错误.

有没有办法从我的控制器的引用访问此接口属性,而无需实现该方法?

Kar*_*rim 0

由于此错误与 JDK 有关,因此您必须在需要该属性的类中创建一个委托方法。