Example usage for org.apache.wicket.application IComponentInstantiationListener IComponentInstantiationListener

List of usage examples for org.apache.wicket.application IComponentInstantiationListener IComponentInstantiationListener

Introduction

In this page you can find the example usage for org.apache.wicket.application IComponentInstantiationListener IComponentInstantiationListener.

Prototype

IComponentInstantiationListener

Source Link

Usage

From source file:com.jolira.wicket.guicier.GuicierWebApplication.java

License:Open Source License

/**
 * Installs the {@link GuicierPageFactory} and a customized
 * {@link IComponentInstantiationListener}.
 * /*  w w w  . ja v  a 2 s  .  c  om*/
 * @see WebApplication#init()
 */
@Override
protected void init() {
    super.init();

    final ComponentInstantiationListenerCollection listeners = getComponentInstantiationListeners();

    listeners.add(new IComponentInstantiationListener() {
        @Override
        public void onInstantiation(final Component component) {
            final Injector i = GuicierWebApplication.this.getInjector();

            i.injectMembers(component);
        }
    });

    setRequestCycleProvider(new IRequestCycleProvider() {
        @Override
        public RequestCycle get(final RequestCycleContext context) {
            return new GuicierWebRequestCycle(context);
        }
    });
}

From source file:dk.netdesign.common.osgi.config.wicket.ConfigurationPageTest.java

License:Apache License

@Before
public void setUp() throws Exception {
    testFile = new File("testFile.test");
    testFile.createNewFile();/* w  w w  . j ava  2 s . c o m*/

    configFactory = new TestConfigurationItemFactory();

    HandlerFactory handlerfactory = new HandlerFactory() {

        @Override
        public <E> ManagedPropertiesProvider getProvider(Class<? super E> configurationType,
                final ManagedPropertiesController controller, E defaults)
                throws InvocationException, InvalidTypeException, InvalidMethodException, DoubleIDException {
            System.out.println("Adding " + configurationType + "->" + controller);
            configFactory.addConfigItem(configurationType,
                    ManagedPropertiesFactory.castToProxy(configurationType, controller));
            return provider;
        }
    };

    factory = new ManagedPropertiesFactory(handlerfactory, null, null);

    tester = new WicketTester(new WebApplication() {
        @Override
        protected void init() {
            super.init(); //To change body of generated methods, choose Tools | Templates.
            getComponentInstantiationListeners().add(new IComponentInstantiationListener() {
                @Override
                public void onInstantiation(Component component) {
                    if (component instanceof InjectingConfigurationPage) {
                        InjectingConfigurationPage icp = (InjectingConfigurationPage) component;
                        System.out.println("Injecting " + configFactory + "\ninto\n" + component);
                        icp.setFactory(configFactory);
                    } else if (component instanceof ConfiguredPage) {
                        ConfiguredPage cp = (ConfiguredPage) component;
                        System.out.println("Injecting " + configFactory + "\ninto\n" + component);
                        cp.setFactory(configFactory);
                    }

                }
            });
        }

        @Override
        public Class<? extends Page> getHomePage() {
            return InjectingConfigurationPage.class;
        }

    });

}