【问题标题】:Can't reference methods in a Bean from a Composite JSF Component无法从复合 JSF 组件引用 Bean 中的方法
【发布时间】:2012-10-15 00:49:42
【问题描述】:

我有以下复合组件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;
}
...
}

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

【问题讨论】:

    标签: jsf composite-component


    【解决方案1】:

    在jsf2上,如果是调用方法,需要加上括号,像这样:

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

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

    【讨论】:

      猜你喜欢
      • 2011-12-14
      • 2011-04-04
      • 2013-05-15
      • 2014-07-02
      • 2012-09-26
      • 2011-07-23
      • 2013-01-24
      • 2012-11-08
      • 2014-03-03
      相关资源
      最近更新 更多