Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding composite component programmatically

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?

like image 806
user3516088 Avatar asked Jun 15 '26 03:06

user3516088


1 Answers

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);
like image 156
BalusC Avatar answered Jun 17 '26 09:06

BalusC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!