【问题标题】:How to reference value declared in cc:attribute in cc:implementation如何在 cc:implementation 中引用 cc:attribute 中声明的值
【发布时间】:2011-12-20 16:10:35
【问题描述】:

我有一个简单的 JSF 2.0 复合组件示例。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:cc="http://java.sun.com/jsf/composite"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core">
<head>
    <title>
        A panel box component
    </title>
</head>
<body>
    <cc:interface>
        <cc:attribute name="model" required="true" type="at.test.Person"/>
    </cc:interface>
    <cc:implementation>
        <h:inputText value="#{model.vorname}">

        </h:inputText>
    </cc:implementation>
</body>

这是我的 JSF 测试页面:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml"
         xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:mc="http://java.sun.com/jsf/composite/mygourmet" >

<h:body>
<h:form>
    <mc:inputTest model="#{person}">

    </mc:inputTest>
    <h:commandButton value=""/>
    <h:outputText value="#{person.vorname}"/>
</h:form>
 </h:body>

</html>

我希望我的复合组件使用&lt;h:inputText&gt; 在 JSF 会话 bean 中保存一个字符串值。但问题是,当我使用&lt;h:commandButton&gt; 提交表单时,我看到以下错误:

Caused by: javax.el.PropertyNotFoundException: /resources/mygourmet/inputTest.xhtml      at line 18 and column 42 value="#{model.vorname}": Target Unreachable, identifier 'model' resolved to null
    at org.apache.myfaces.view.facelets.el.TagValueExpression.getType(TagValueExpression.java:73)
    at org.apache.myfaces.shared_impl.renderkit._SharedRendererUtils.findUIOutputConverter(_SharedRendererUtils.java:77)

【问题讨论】:

    标签: jsf-2 facelets composite-component


    【解决方案1】:

    您需要通过#{cc.attrs.&lt;name&gt;} 引用复合组件属性值,其中&lt;name&gt; 是属性名称。所以,应该这样做:

    <h:inputText value="#{cc.attrs.model.vorname}">
    

    另见:


    与具体问题无关,合成中的所有&lt;html&gt;&lt;head&gt;&lt;body&gt; 都是不必要的。我建议使用&lt;ui:component&gt;,因为这样更清楚。有关示例,另请参阅 our composite component wiki page

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-02
      • 1970-01-01
      • 2019-03-29
      • 2016-03-30
      • 1970-01-01
      • 2020-09-06
      相关资源
      最近更新 更多