以编程方式添加复合组件 [英] Adding composite component programmatically

查看:64
本文介绍了以编程方式添加复合组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式将以下复合组件包括在内:

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆