3

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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user3516088
  • 155
  • 2
  • 11

1 Answers1

3

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);
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555