在复合组件中装饰标准组件,如何继承属性?
我想知道是否有一种很好的方法来用复合组件来装饰组件?
示例:
<composite:implementation>
<div style="someFancyClass">
<h:inputText value="#{cc.attrs.value}" />
</div>
</composite:implementation>
在本例中,value 属性将传递到所包含的
。但是所有其他属性又如何呢?我是否必须在
部分声明所有这些?
最好能够从标准组件中继承某种类型,以便例如
的 maxlength 属性在复合组件中自动可用。
I am wondering if there is a nice way to decorate components with composite components?
Example:
<composite:implementation>
<div style="someFancyClass">
<h:inputText value="#{cc.attrs.value}" />
</div>
</composite:implementation>
In this case the value attribute is passed through to the contained <h:inputText>
. But what about all the other attributes? Do I have to declare all of them in the <composite:interface>
section?
It would be nice to have some kind of inheritance from standard components, so that e.g. the maxlength attribute of <h:inputText>
is automatically available at the composite component.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有必要,您可以只使用
maxlength="#{cc.attrs .maxlength}"
,无需将其声明为
。然而,这对于记录目的来说是不利的。开发人员不会看到此属性出现在复合组件的文档中(例如,IDE 自动完成功能可能会使用该属性)。不可能。为此,您确实需要创建一个完整的自定义
UIInput
组件和/或Renderer
(在您的特定情况下,仅渲染器就足够了)。Not necessary, you can just use
maxlength="#{cc.attrs.maxlength}"
without the need to declare it as<composite:attribute>
. However, this is bad for documentatory purposes. The developer would not see this attribute to appear in the composite component's documentation (which might be used by IDE autocompletion, for example).That's not possible. For that you'd really need to create a fullworthy custom
UIInput
component and/or aRenderer
(in your particular case, just the renderer ought to be sufficient).我在这里提供了一个有关如何装饰复合组件的示例 https://stackoverflow.com/a/8881510/1151983
但是,这并不提供真正的继承,而是一种在一组相似的复合组件之间共享公共内容的方法。
I provided an example on how to decorate a composite component here https://stackoverflow.com/a/8881510/1151983
However, this does not provide real inheritance, but a way to share common stuff between a set of similar composite components.