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

<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。我该如何实现?

最佳答案

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);

09-12 12:53