Newer Version Available

This content describes an older version of this product. View Latest

Server-Side Runtime Binding of Components

A provider enables you to use an abstract component or an interface in markup. The framework uses the provider to determine the concrete component to use at runtime.

Server-side providers are more common, but if you don't need to access the server when you're creating a component, you can use a client-side provider instead.

Set the provider system attribute in the <aura:component> tag of an abstract component or interface to point to the server-side provider Java class.

The syntax of the provider system attribute is provider="java://package.class" where package.class is the fully qualified name for the class.

A Java provider must:

  • Include the @Provider annotation above the class definition
  • Implement either the ComponentDescriptorProvider or ComponentConfigProvider interface

Existing providers haven’t been refactored to use the interfaces. The older method of creating a provider doesn’t use interfaces and uses a static provide() method to return the concrete component. For an example, see InputOptionProvider.java. Use the provider interfaces when you are creating a new provider.

Note

At runtime, a provider has access to a shell of the abstract component or interface, including any attribute values that have been set. The model isn't constructed yet so you can't access it. The provide() method can examine the attribute values that are set on the component, and return a descriptor of the non-abstract component type that should be used.

A provider should only return concrete components that are sub-components of a single base component or implement an interface. Aura doesn't currently enforce this restriction, but will in a future release.

Note

ComponentDescriptorProvider

Use the ComponentDescriptorProvider interface to return a DefDescriptor describing the concrete component to use when you don’t need to set attributes for the component. For example:

1swfobject.registerObject("clippy.codeblock-0", "9");@Provider
2public class SampleDescProvider implements ComponentDescriptorProvider {
3
4    public DefDescriptor<ComponentDef> provide() {
5        DefDescriptor defDesc = null;
6
7        // logic to determine DefDescriptor to set and return.
8
9        return defDesc;
10    }
11}

ComponentConfigProvider

Use the ComponentConfigProvider interface to return a ComponentConfig, which describes the concrete component to use in a DefDescriptor and enables you to set attributes for the component. For example:

1swfobject.registerObject("clippy.codeblock-1", "9");@Provider
2public class SampleConfigProvider implements ComponentConfigProvider {
3
4    public ComponentConfig<ComponentDef> provide() {
5        ComponentConfig cmpConfig = null;
6
7        // logic to determine DefDescriptor
8        // and attributes to set.
9
10        return cmpConfig;
11    }
12}

Declaring Provider Dependencies

The Aura framework automatically tracks dependencies between definitions, such as components. However, if a component uses a provider that instantiates components that are not directly referenced elsewhere, use <aura:dependency> in the component to explicitly tell the framework about the dependency, which wouldn't otherwise be discovered by Aura.