我正在实现我的自定义组件,如下所示。已将此文件放置在 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>
但身高什么也没返回。
自定义组件的使用方式如下
<my:mycustom height="40"></my:mycustom>
我在这里做错了什么。任何人请帮助我做到这一点。
我发现了问题,使用命名空间作为复合来获取属性(#{composite.attrs.height}(但这似乎是不正确的,并且使用了 cc 而不是复合及其正确返回。
{cc.attrs.height}
晚了,但是,我想回答你的问题,因为这里还没有有效的答案。
甚至,您已经找到了空值原因,请将此作为答案的建议。
你发现什么:{cc.attrs.height}是正确的,你必须通过"cc"访问属性,它不会改变命名空间,把它作为一个快速访问关键字,如"会话"、"请求"等。
让我继续我的建议。
您的组件定义具有 html 和正文标记。这通常不适用于组件定义。由于组件是页面的一部分,因此可以按如下方式定义和使用。
注意:您已将文件放在正确的位置,但我建议将文件夹设置为">组件",例如在资源文件夹中。然后,它将通过以下命名空间定义在任何页面上可用:
xmlns:components="http://java.sun.com/jsf/composite/components"
我的第一组件.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>