以编程方式添加复合组件 [英] Adding composite component programmatically
问题描述
我想以编程方式将以下复合组件包括在内:
I would like to include below composite component programmatically:
<composite:interface>
<composite:attribute name="sampleBean" />
<composite:attribute name="autoCompleteMethod"
method-signature="java.util.List autoCompleteMethod(java.lang.String)" />
</composite:interface>
在 Omnifaces 中,有一个功能:
// Programmatically include composite component.
Components.includeCompositeComponent(someParentComponent, libraryName, resourceName, id);
但是,我不清楚如何在获得的UIComponent实例中指定autoCompleteMethod
.我该如何实现?
However, it isn't clear to me how to specify the autoCompleteMethod
in the obtained UIComponent instance. How can I achieve this?
推荐答案
includeCompositeComponent()
返回表示复合实现的UIComponent
实例.
The includeCompositeComponent()
returns an UIComponent
instance representing the composite implementation.
UIComponent composite = Components.includeCompositeComponent(someParentComponent, libraryName, resourceName, id);
它的所有属性都可以被UIComponent#getAttributes()
用作Map
.
All of its attributes are available as a Map
by UIComponent#getAttributes()
.
Map<String, Object> attributes = composite.getAttributes();
You can use Components#createMethodExpression()
to create an EL method expression. Assuming that you intend to specify #{bean.complete}
, here's an example:
MethodExpression autoCompleteMethod = Components.createMethodExpression("#{bean.complete}", List.class, String.class);
现在,只需将其设置为属性!
Now, just set it as attribute!
attributes.put("autoCompleteMethod", autoCompleteMethod);
这篇关于以编程方式添加复合组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!