无法从Composite JSF Component引用Bean中的方法

时间:2012-10-24 21:53:26

标签: jsf composite-component

我有以下复合组件TestCC.xhtml:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:cc="http://java.sun.com/jsf/composite">
<cc:interface>
<cc:attribute name="manager" method-signature="java.lang.String helloTest()" required="true"/>
</cc:interface>
<cc:implementation>
Hello #{cc.attrs.manager} !!!!!!!!!!!!!!!!!!!!!
</cc:implementation>
</html>

当我尝试在JSFF文件中调用它时:

....
<icc:TestCC manager="#{viewScope.PatientClinicalBean.helloTest}"/>
...

页面在我的复合标记处崩溃,并在控制台中显示以下消息:

javax.el.ELException: //C:/Documents and Settings/tlam/Application Data/JDeveloper/system11.1.2.3.39.62.76.1/o.j2ee/drs/iCHIP/ViewControllerWebApp.war/WEB-INF/classes/META-INF/resources/IchipComponent/TestCC.xhtml: javax.el.PropertyNotFoundException: //C:/Documents and Settings/tlam/Application Data/JDeveloper/system11.1.2.3.39.62.76.1/o.j2ee/drs/iCHIP/ViewControllerWebApp.war/Patient/Profile/Clinical.jsff @13,86 manager="#{viewScope.PatientClinicalBean.helloTest}": The class 'patient.profile.PatientClinicalBean' does not have the property 'helloTest'.

但是我的托管bean确实有一个公共的String helloTest()方法,以及在我的JSFF页面的其他地方工作正常的其他方法:

public class PatientClinicalBean{
String test = "TESTING"; 
...
public String helloTest() {
  return test;
}
...
}

我用不同的方法尝试了很多次,都有相同的结果。然而,如果我的复合组件只输出一个字符串,我输入表达式直接访问字符串测试字段,它正确执行。当其他方法调用在同一个JSFF页面中正常工作时,我似乎无法仅从我的复合组件引用PatientClinicalBean中的任何方法。我在网上看到的所有其他例子都没有问题,就像我一样,我错过了什么?!

1 个答案:

答案 0 :(得分:0)

在jsf2上,如果你正在调用一个方法,你需要添加括号,如下所示:

....
<icc:TestCC manager="#{viewScope.PatientClinicalBean.helloTest()}"/>
...

否则jsf会将其解释为一个字段,并尝试找到方法getHelloTest()。

相关问题