Adding composite component programmatically

时光总嘲笑我的痴心妄想 提交于 2019-12-10 10:08:44

问题


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>

In Omnifaces, there is a function:

// Programmatically include composite component.
Components.includeCompositeComponent(someParentComponent, libraryName, resourceName, id);

However, it isn't clear to me how to specify the autoCompleteMethod in the obtained UIComponent instance. How can I achieve this?


回答1:


The includeCompositeComponent() returns an UIComponent instance representing the composite implementation.

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

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


来源:https://stackoverflow.com/questions/24410194/adding-composite-component-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!