以编程方式添加复合组件

时间:2014-06-25 13:33:35

标签: jsf composite-component omnifaces

我想以编程方式包含下面的复合组件:

<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。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:3)

includeCompositeComponent()返回表示复合实现的UIComponent实例。

UIComponent composite = Components.includeCompositeComponent(someParentComponent, libraryName, resourceName, id);

所有属性均由Map UIComponent#getAttributes()提供。

Map<String, Object> attributes = composite.getAttributes();

您可以使用Components#createMethodExpression()创建EL方法表达式。假设您打算指定#{bean.complete},这里有一个例子:

MethodExpression autoCompleteMethod = Components.createMethodExpression("#{bean.complete}", List.class, String.class);

现在,只需将其设置为属性!

attributes.put("autoCompleteMethod", autoCompleteMethod);