Provinding a component instance to the client components of a container

This example will show you how you can pass objects (components) from the container to their clients. There was a questioin on the devolpers list, how to pass objects like username from the main method to the all Client Components.

First declare the Object you want to pass.

class MyComponent
{
 String ROLE=MyComponent.class.getName();
 String username;

  ... setter and getter for username if you wish ..
}

In the initialization of the raplaContainer in org.rapla.Main you need to add the component instance. Insert the following lines before the lookup of the client service sm.lookup(ClientService.ROLE);

MyComponent myComponent = new MyComponent();
myComponent.setUsername ("roberto");
raplaContainer.addContainerProvidedComponentInstance( MyComponent.ROLE, myComponent);

In the client component use the following code to access My Component:

  myComponent = (MyComponent) getContext().lookup( MyComponent.ROLE );