Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
复合属性在jsf自定义组件中返回null_Jsf_Jsf 2_Custom Component - Fatal编程技术网

复合属性在jsf自定义组件中返回null

复合属性在jsf自定义组件中返回null,jsf,jsf-2,custom-component,Jsf,Jsf 2,Custom Component,我正在实现我的自定义组件,如下所示。将此文件放置在web->resource文件夹中 <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" >

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

<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>

#{composite.attrs.height}
但是attrs.height什么也没有返回

自定义组件的使用方式如下所示

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


我在这里犯的错误。任何人请帮我做这件事。

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


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

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

您所发现的:{cc.attrs.height}是正确的,您必须通过“cc”访问属性。它不改变名称空间,将其作为快速访问关键字,如“session”、“request”等

让我接着谈谈我的建议

组件定义有htmlbody标记。通常不适用于组件定义。由于组件是页面的一部分,因此可以按如下方式定义和使用

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

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>