Directory

← Back

Contextual Object Lookup

Inter-component communication and service layer integration

Author

Rating

Popularity

<100

A decoupled type safe mechanism for inter component communication and service layer integration.

Can be used for integrating any service lookup mechanism or IoC container (Spring, Guice, Tapestry IoC) into a Vaadin application. The Vaadin components using the services will have no dependencies on the specific service layer technology, making it easier to switch.

The typical scenarios where Contextual Object Lookup (COL) is used is as follows:

  1. A component deep down in the hierarchy needs to communicate with some other component closer to the root of the hierarchy.

  2. A component deep down in the hierarchy needs to operate on an object that is provided by some other component closer to the root of the hierarchy.

  3. A component needs access to the service layer.

Sample code

public ParentComponent extends AbstractComponent implements ContextProvider {
    private ContextHolder ch = new ContextHolder();

    public ParentComponent() {
        ch.add(new Customer());
    }

    public <T> T getContext(Class<T> type) {
        return ch.getContext(type);
    }
}

public ChildButton extends Button implements Button.ClickListener {
    public ChildButton() {
        super(this);
    }

    public void buttonClick(ClickEvent event) {
        Customer customer = Context.from(this).locate(Customer.class);
        customer.doSomething();
    }
}
public MyApplication extends Application implements ContextProvider {
  public <T> T getContext(Class<T> type) {
      ServletContext sc = ((WebApplicationContext) getContext()).getHttpSession().getServletContext();
      return WebApplicationContextUtils.getRequiredWebApplicationContext(sc).getBean(type);
  }
}

public MyComponent extends AbstractComponent {
  public void attach() {
    // Note: The context cannot be retrieved in the constructor as the component
    // has yet to be attached to the component tree.
    MySpringService mySpringService = Context.from(this).locate(MySpringService.class);
  }
}
public class MyComponent extends AbstractComponent {

    public void attach() {
        MyApplication application = Context.from(this).locate(MyApplication.class);
    }

}
public class MyChildComponent extends AbstractComponent {

    public void attach() {
        MyAncestorComponent mac = Context.from(this).locate(MyAncestorComponent.class);
    }
}

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

Initial release to Vaadin Directory.

Released
2011-09-05
Maturity
EXPERIMENTAL
License
Apache License 2.0

Compatibility

Framework
Vaadin 6.2+
Browser
Browser Independent

Contextual Object Lookup - Vaadin Add-on Directory

Inter-component communication and service layer integration Contextual Object Lookup - Vaadin Add-on Directory
A decoupled type safe mechanism for inter component communication and service layer integration. Can be used for integrating any service lookup mechanism or IoC container (Spring, Guice, Tapestry IoC) into a Vaadin application. The Vaadin components using the services will have no dependencies on the specific service layer technology, making it easier to switch. The typical scenarios where Contextual Object Lookup (COL) is used is as follows: 1. A component deep down in the hierarchy needs to communicate with some other component closer to the root of the hierarchy. 2. A component deep down in the hierarchy needs to operate on an object that is provided by some other component closer to the root of the hierarchy. 3. A component needs access to the service layer.
Author Homepage
Issue Tracker
Source Code

Contextual Object Lookup version 0.1.1
Initial release to Vaadin Directory.

Online