问题
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