我想以编程方式包含下面的复合组件:
<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
。我怎样才能做到这一点?
答案 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);