jsf 自定义组件中的复合属性 returns null
composite attributes returns null in jsf custom components
我正在实现我的自定义组件,如下所示。放置此文件 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 return什么都没有。
自定义组件使用如下
<my:mycustom height="40"></my:mycustom>
我在这里做错了什么。任何人都请帮助我做到这一点。
我发现了问题,使用命名空间作为组合来获取属性(#{composite.attrs.height})
但这似乎是不正确的,并且使用 cc 而不是 composite 及其 returns 正确。
{cc.attrs.height}
我知道有点晚了,但是,我想回答你的问题,因为这里还没有有效的答案..
偶,你已经找到了空值的原因,请以此为答答疑..
您发现:{cc.attrs.height} 是正确的,您必须通过 "cc" 访问属性,它不会改变命名空间,将其作为快速访问关键字,如 "session"、"request" 等
让我继续我的建议..
您的组件定义有 html 和 body 标签。通常不用于组件定义。因为组件是页面的一部分,所以可以如下定义和使用..
注意:您已将文件放在正确的位置,但我建议在资源文件夹中创建一个文件夹“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>
我正在实现我的自定义组件,如下所示。放置此文件 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 return什么都没有。
自定义组件使用如下
<my:mycustom height="40"></my:mycustom>
我在这里做错了什么。任何人都请帮助我做到这一点。
我发现了问题,使用命名空间作为组合来获取属性(#{composite.attrs.height}) 但这似乎是不正确的,并且使用 cc 而不是 composite 及其 returns 正确。
{cc.attrs.height}
我知道有点晚了,但是,我想回答你的问题,因为这里还没有有效的答案..
偶,你已经找到了空值的原因,请以此为答答疑..
您发现:{cc.attrs.height} 是正确的,您必须通过 "cc" 访问属性,它不会改变命名空间,将其作为快速访问关键字,如 "session"、"request" 等
让我继续我的建议..
您的组件定义有 html 和 body 标签。通常不用于组件定义。因为组件是页面的一部分,所以可以如下定义和使用..
注意:您已将文件放在正确的位置,但我建议在资源文件夹中创建一个文件夹“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>