【问题标题】:composite attributes returns null in jsf custom components复合属性在 jsf 自定义组件中返回 null
【发布时间】:2017-11-11 07:05:08
【问题描述】:

我正在实现我的自定义组件,如下所示。将此文件放在 web-> 资源文件夹

<html
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:composite="http://java.sun.com/jsf/composite"
      >
    <h:body>
        <composite:interface>
            <composite:attribute name="width" default="300"/>
            <composite:attribute name="height" default="400"/>
        </composite:interface>
        <composite:implementation>
            <h:inputText style="height: #{composite.attrs.height}px"></h:inputText>
            <span> #{composite.attrs.height}</span>
        </composite:implementation>
    </h:body>
</html>

但是 attrs.height 什么也不返回。

自定义组件如下所示

<my:mycustom  height="40"></my:mycustom>

我在这里做错了什么。任何人都请帮我这样做。

【问题讨论】:

    标签: jsf jsf-2 custom-component


    【解决方案1】:

    我找到了问题,使用命名空间作为复合来获取属性(#{composite.attrs.height}) 但这似乎是不正确的,并且使用 cc 而不是 Composite 并且它的返回正确。

    {cc.attrs.height}

    【讨论】:

      【解决方案2】:

      我知道有点晚了,但是我想回答你的问题,因为这里还没有有效的答案..

      即使,您已经找到了空值的原因,请将此作为回答建议..

      你的发现:{cc.attrs.height}是对的,你必须通过“cc”访问属性,它不会改变命名空间,把它作为快速访问关键字比如“会话”、“请求”等。

      让我继续我的建议..

      您的组件定义有 htmlbody 标签。通常不适用于组件定义。因为组件是页面的一部分,所以可以如下定义和使用..

      注意:您已将文件放在正确的位置,但我建议在资源文件夹中创建一个文件夹“components”。然后,它将通过以下命名空间定义在任何页面上可用:

      xmlns:components="http://java.sun.com/jsf/composite/components"
      

      myFirstComponent.xhtml

      <ui:component xmlns=""
                    xmlns:ui="http://java.sun.com/jsf/facelets"
                    xmlns:composite="http://java.sun.com/jsf/composite" 
                    xmlns:p="http://primefaces.org/ui"
                    xmlns:f="http://java.sun.com/jsf/core">
      
          <composite:interface>
              <!-- Your attributes goes here -->
              <composite:attribute name="sampleAttributeName" default="@form"/>
          </composite:interface>
      
          <composite:implementation>
              <!-- Your implementation goes here -->
          </composite:implementation>
      </ui:component>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-07-30
        • 1970-01-01
        • 2017-11-07
        • 1970-01-01
        • 2021-09-16
        • 1970-01-01
        • 2014-02-06
        • 2019-01-24
        相关资源
        最近更新 更多