You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Peter Mularien (JIRA)" <ji...@apache.org> on 2007/11/09 20:25:50 UTC

[jira] Created: (WICKET-1143) Modify InjectorHolder to allow for storage of multiple types of Injectors (for Guice support)

Modify InjectorHolder to allow for storage of multiple types of Injectors (for Guice support)
---------------------------------------------------------------------------------------------

                 Key: WICKET-1143
                 URL: https://issues.apache.org/jira/browse/WICKET-1143
             Project: Wicket
          Issue Type: Improvement
          Components: wicket, wicket-guice
    Affects Versions: 1.3.0-beta4
            Reporter: Peter Mularien


As per discussion on the mailing list:
http://www.nabble.com/Question-about-Guice-integration-with-Wicket-1.3-beta-4-tf4778901.html#a13672025

InjectorHolder should play nicely with GuiceComponentInjector, and allow for mixed systems using both Spring and Guice. Thanks!

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (WICKET-1143) Modify InjectorHolder to allow for storage of multiple types of Injectors (for Guice support)

Posted by "Alastair Maw (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-1143?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alastair Maw reassigned WICKET-1143:
------------------------------------

    Assignee: Alastair Maw

> Modify InjectorHolder to allow for storage of multiple types of Injectors (for Guice support)
> ---------------------------------------------------------------------------------------------
>
>                 Key: WICKET-1143
>                 URL: https://issues.apache.org/jira/browse/WICKET-1143
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket, wicket-guice
>    Affects Versions: 1.3.0-beta4
>            Reporter: Peter Mularien
>            Assignee: Alastair Maw
>
> As per discussion on the mailing list:
> http://www.nabble.com/Question-about-Guice-integration-with-Wicket-1.3-beta-4-tf4778901.html#a13672025
> InjectorHolder should play nicely with GuiceComponentInjector, and allow for mixed systems using both Spring and Guice. Thanks!

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (WICKET-1143) Modify InjectorHolder to allow for storage of multiple types of Injectors (for Guice support)

Posted by "Damian Nowak (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-1143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12915011#action_12915011 ] 

Damian Nowak edited comment on WICKET-1143 at 9/26/10 2:06 PM:
---------------------------------------------------------------

I managed to create some almost-working Injector for both Java EE and Spring. EJBs and Spring Beans get injected with this.

Almost-working because I get serialization exceptions - I don't know why Wicket needs the class serializable as the classes from Java EE injector and Spring injector are not and they work.

If anyone is able to correct it so that no serialization exceptions are thrown, feel free.

in Application.init():

{noformat}
addComponentInstantiationListener(new SpringComponentInjector(this));
addComponentInstantiationListener(new JavaEEComponentInjector(this, createNamingStrategy()));
final SpringAndJavaEeInjector springAndJavaEeInjector = new SpringAndJavaEeInjector(this, new StandardJndiNamingStrategy()); // I use my own naming strategy, StandardJndiNamingStrategy is the default
InjectorHolder.setInjector(springAndJavaEeInjector);
{noformat}

{noformat}
import java.io.Serializable;
import java.lang.reflect.Field;
import org.apache.wicket.IClusterable;
import org.apache.wicket.injection.ConfigurableInjector;
import org.apache.wicket.injection.IFieldValueFactory;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.spring.ISpringContextLocator;
import org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.wicketstuff.javaee.injection.JavaEEProxyFieldValueFactory;
import org.wicketstuff.javaee.naming.IJndiNamingStrategy;

public class SpringAndJavaEeInjector extends ConfigurableInjector implements Serializable {

	private final SpringAndJavaEeFieldValueFactory factory;

	public SpringAndJavaEeInjector(final WebApplication webApplication, final IJndiNamingStrategy namingStrategy) {
		JavaEEProxyFieldValueFactory javaEeFactory = new JavaEEProxyFieldValueFactory(namingStrategy);
		AnnotProxyFieldValueFactory springFactory = new AnnotProxyFieldValueFactory(new ISpringContextLocator() {

			@Override
			public ApplicationContext getSpringContext() {
				return WebApplicationContextUtils.getRequiredWebApplicationContext(webApplication.getServletContext());
			}
		}, true);
		factory = new SpringAndJavaEeFieldValueFactory(javaEeFactory, springFactory);
	}

	@Override
	protected IFieldValueFactory getFieldValueFactory() {
		return factory;
	}

	private static class SpringAndJavaEeFieldValueFactory implements IFieldValueFactory {

		private final JavaEEProxyFieldValueFactory javaEeFactory;

		private final AnnotProxyFieldValueFactory springFactory;

		public SpringAndJavaEeFieldValueFactory(JavaEEProxyFieldValueFactory javaEeFactory, AnnotProxyFieldValueFactory springFactory) {
			this.javaEeFactory = javaEeFactory;
			this.springFactory = springFactory;
		}

		@Override
		public Object getFieldValue(Field field, Object fieldOwner) {
			try {
				final Object fieldValue = javaEeFactory.getFieldValue(field, fieldOwner);
				if (fieldValue == null) {
					throw new RuntimeException();
				}
				return fieldValue;
			} catch (Exception e) {
				return springFactory.getFieldValue(field, fieldOwner);
			}
		}

		@Override
		public boolean supportsField(Field field) {
			final boolean supportsField = javaEeFactory.supportsField(field);
			if (supportsField) {
				return true;
			}
			return springFactory.supportsField(field);
		}
	}

}
{noformat}

Ehh, Wiki syntax is turned off here. Here is a formatted and highlighted code: http://wklej.org/id/393829/

      was (Author: nowaker):
    I managed to create some almost-working Injector for both Java EE and Spring. EJBs and Spring Beans get injected with this.

Almost-working because I get serialization exceptions - I don't know why Wicket needs the class serializable as the classes from Java EE injector and Spring injector are not and they work.

in Application.init():

{noformat}
addComponentInstantiationListener(new SpringComponentInjector(this));
addComponentInstantiationListener(new JavaEEComponentInjector(this, createNamingStrategy()));
final SpringAndJavaEeInjector springAndJavaEeInjector = new SpringAndJavaEeInjector(this, new StandardJndiNamingStrategy()); // I use my own naming strategy, StandardJndiNamingStrategy is the default
InjectorHolder.setInjector(springAndJavaEeInjector);
{noformat}

{noformat}
import java.io.Serializable;
import java.lang.reflect.Field;
import org.apache.wicket.IClusterable;
import org.apache.wicket.injection.ConfigurableInjector;
import org.apache.wicket.injection.IFieldValueFactory;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.spring.ISpringContextLocator;
import org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.wicketstuff.javaee.injection.JavaEEProxyFieldValueFactory;
import org.wicketstuff.javaee.naming.IJndiNamingStrategy;

public class SpringAndJavaEeInjector extends ConfigurableInjector implements Serializable {

	private final SpringAndJavaEeFieldValueFactory factory;

	public SpringAndJavaEeInjector(final WebApplication webApplication, final IJndiNamingStrategy namingStrategy) {
		JavaEEProxyFieldValueFactory javaEeFactory = new JavaEEProxyFieldValueFactory(namingStrategy);
		AnnotProxyFieldValueFactory springFactory = new AnnotProxyFieldValueFactory(new ISpringContextLocator() {

			@Override
			public ApplicationContext getSpringContext() {
				return WebApplicationContextUtils.getRequiredWebApplicationContext(webApplication.getServletContext());
			}
		}, true);
		factory = new SpringAndJavaEeFieldValueFactory(javaEeFactory, springFactory);
	}

	@Override
	protected IFieldValueFactory getFieldValueFactory() {
		return factory;
	}

	private static class SpringAndJavaEeFieldValueFactory implements IFieldValueFactory {

		private final JavaEEProxyFieldValueFactory javaEeFactory;

		private final AnnotProxyFieldValueFactory springFactory;

		public SpringAndJavaEeFieldValueFactory(JavaEEProxyFieldValueFactory javaEeFactory, AnnotProxyFieldValueFactory springFactory) {
			this.javaEeFactory = javaEeFactory;
			this.springFactory = springFactory;
		}

		@Override
		public Object getFieldValue(Field field, Object fieldOwner) {
			try {
				final Object fieldValue = javaEeFactory.getFieldValue(field, fieldOwner);
				if (fieldValue == null) {
					throw new RuntimeException();
				}
				return fieldValue;
			} catch (Exception e) {
				return springFactory.getFieldValue(field, fieldOwner);
			}
		}

		@Override
		public boolean supportsField(Field field) {
			final boolean supportsField = javaEeFactory.supportsField(field);
			if (supportsField) {
				return true;
			}
			return springFactory.supportsField(field);
		}
	}

}
{noformat}

If anyone is able to correct it so that no serialization exceptions are thrown, feel free.
  
> Modify InjectorHolder to allow for storage of multiple types of Injectors (for Guice support)
> ---------------------------------------------------------------------------------------------
>
>                 Key: WICKET-1143
>                 URL: https://issues.apache.org/jira/browse/WICKET-1143
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket, wicket-guice
>    Affects Versions: 1.3.0-beta4
>            Reporter: Peter Mularien
>            Assignee: Martin Grigorov
>
> As per discussion on the mailing list:
> http://www.nabble.com/Question-about-Guice-integration-with-Wicket-1.3-beta-4-tf4778901.html#a13672025
> InjectorHolder should play nicely with GuiceComponentInjector, and allow for mixed systems using both Spring and Guice. Thanks!

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-1143) Modify InjectorHolder to allow for storage of multiple types of Injectors (for Guice support)

Posted by "Guðmundur Bjarni Ólafsson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-1143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12592173#action_12592173 ] 

Guðmundur Bjarni Ólafsson commented on WICKET-1143:
---------------------------------------------------

Rather than exposing multiple injectors via the InjectorHolder, this could be solved by chaining the Injectors behind the Holder. That way when you call InjectorHolder.getInjector.inject(object), it would iterate through each injector it knows about and perform the injection. The order of the injectors could be the order in which they are added as instantiation listeners to the application. 

By solving this issue in that way, then in most cases we wouldn't break any existing apps, help people who are migrating from Injection framework A to B and allow Guice to be pulled out via the InjectorHolder.

> Modify InjectorHolder to allow for storage of multiple types of Injectors (for Guice support)
> ---------------------------------------------------------------------------------------------
>
>                 Key: WICKET-1143
>                 URL: https://issues.apache.org/jira/browse/WICKET-1143
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket, wicket-guice
>    Affects Versions: 1.3.0-beta4
>            Reporter: Peter Mularien
>            Assignee: Alastair Maw
>
> As per discussion on the mailing list:
> http://www.nabble.com/Question-about-Guice-integration-with-Wicket-1.3-beta-4-tf4778901.html#a13672025
> InjectorHolder should play nicely with GuiceComponentInjector, and allow for mixed systems using both Spring and Guice. Thanks!

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-1143) Modify InjectorHolder to allow for storage of multiple types of Injectors (for Guice support)

Posted by "Damian Nowak (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-1143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12915011#action_12915011 ] 

Damian Nowak commented on WICKET-1143:
--------------------------------------

I managed to create some almost-working Injector for both Java EE and Spring. EJBs and Spring Beans get injected with this.

Almost-working because I get serialization exceptions - I don't know why Wicket needs the class serializable as the classes from Java EE injector and Spring injector are not and they work.

in Application.init():

{noformat}
addComponentInstantiationListener(new SpringComponentInjector(this));
addComponentInstantiationListener(new JavaEEComponentInjector(this, createNamingStrategy()));
final SpringAndJavaEeInjector springAndJavaEeInjector = new SpringAndJavaEeInjector(this, new StandardJndiNamingStrategy()); // I use my own naming strategy, StandardJndiNamingStrategy is the default
InjectorHolder.setInjector(springAndJavaEeInjector);
{noformat}

{noformat}
import java.io.Serializable;
import java.lang.reflect.Field;
import org.apache.wicket.IClusterable;
import org.apache.wicket.injection.ConfigurableInjector;
import org.apache.wicket.injection.IFieldValueFactory;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.spring.ISpringContextLocator;
import org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.wicketstuff.javaee.injection.JavaEEProxyFieldValueFactory;
import org.wicketstuff.javaee.naming.IJndiNamingStrategy;

public class SpringAndJavaEeInjector extends ConfigurableInjector implements Serializable {

	private final SpringAndJavaEeFieldValueFactory factory;

	public SpringAndJavaEeInjector(final WebApplication webApplication, final IJndiNamingStrategy namingStrategy) {
		JavaEEProxyFieldValueFactory javaEeFactory = new JavaEEProxyFieldValueFactory(namingStrategy);
		AnnotProxyFieldValueFactory springFactory = new AnnotProxyFieldValueFactory(new ISpringContextLocator() {

			@Override
			public ApplicationContext getSpringContext() {
				return WebApplicationContextUtils.getRequiredWebApplicationContext(webApplication.getServletContext());
			}
		}, true);
		factory = new SpringAndJavaEeFieldValueFactory(javaEeFactory, springFactory);
	}

	@Override
	protected IFieldValueFactory getFieldValueFactory() {
		return factory;
	}

	private static class SpringAndJavaEeFieldValueFactory implements IFieldValueFactory {

		private final JavaEEProxyFieldValueFactory javaEeFactory;

		private final AnnotProxyFieldValueFactory springFactory;

		public SpringAndJavaEeFieldValueFactory(JavaEEProxyFieldValueFactory javaEeFactory, AnnotProxyFieldValueFactory springFactory) {
			this.javaEeFactory = javaEeFactory;
			this.springFactory = springFactory;
		}

		@Override
		public Object getFieldValue(Field field, Object fieldOwner) {
			try {
				final Object fieldValue = javaEeFactory.getFieldValue(field, fieldOwner);
				if (fieldValue == null) {
					throw new RuntimeException();
				}
				return fieldValue;
			} catch (Exception e) {
				return springFactory.getFieldValue(field, fieldOwner);
			}
		}

		@Override
		public boolean supportsField(Field field) {
			final boolean supportsField = javaEeFactory.supportsField(field);
			if (supportsField) {
				return true;
			}
			return springFactory.supportsField(field);
		}
	}

}
{noformat}

If anyone is able to correct it so that no serialization exceptions are thrown, feel free.

> Modify InjectorHolder to allow for storage of multiple types of Injectors (for Guice support)
> ---------------------------------------------------------------------------------------------
>
>                 Key: WICKET-1143
>                 URL: https://issues.apache.org/jira/browse/WICKET-1143
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket, wicket-guice
>    Affects Versions: 1.3.0-beta4
>            Reporter: Peter Mularien
>            Assignee: Martin Grigorov
>
> As per discussion on the mailing list:
> http://www.nabble.com/Question-about-Guice-integration-with-Wicket-1.3-beta-4-tf4778901.html#a13672025
> InjectorHolder should play nicely with GuiceComponentInjector, and allow for mixed systems using both Spring and Guice. Thanks!

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-1143) Modify InjectorHolder to allow for storage of multiple types of Injectors (for Guice support)

Posted by "Eelco Hillenius (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-1143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12894916#action_12894916 ] 

Eelco Hillenius commented on WICKET-1143:
-----------------------------------------

Don't know if it is that important, but if it is, chaining sounds reasonable to me.

> Modify InjectorHolder to allow for storage of multiple types of Injectors (for Guice support)
> ---------------------------------------------------------------------------------------------
>
>                 Key: WICKET-1143
>                 URL: https://issues.apache.org/jira/browse/WICKET-1143
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket, wicket-guice
>    Affects Versions: 1.3.0-beta4
>            Reporter: Peter Mularien
>            Assignee: Martin Grigorov
>
> As per discussion on the mailing list:
> http://www.nabble.com/Question-about-Guice-integration-with-Wicket-1.3-beta-4-tf4778901.html#a13672025
> InjectorHolder should play nicely with GuiceComponentInjector, and allow for mixed systems using both Spring and Guice. Thanks!

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-1143) Modify InjectorHolder to allow for storage of multiple types of Injectors (for Guice support)

Posted by "Damian Nowak (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-1143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12914883#action_12914883 ] 

Damian Nowak commented on WICKET-1143:
--------------------------------------

Very important for me. I needed to introduce Spring and found it impossible since I already use Java EE 5 and JavaEEComponentInjector from wicketstuff.

> Modify InjectorHolder to allow for storage of multiple types of Injectors (for Guice support)
> ---------------------------------------------------------------------------------------------
>
>                 Key: WICKET-1143
>                 URL: https://issues.apache.org/jira/browse/WICKET-1143
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket, wicket-guice
>    Affects Versions: 1.3.0-beta4
>            Reporter: Peter Mularien
>            Assignee: Martin Grigorov
>
> As per discussion on the mailing list:
> http://www.nabble.com/Question-about-Guice-integration-with-Wicket-1.3-beta-4-tf4778901.html#a13672025
> InjectorHolder should play nicely with GuiceComponentInjector, and allow for mixed systems using both Spring and Guice. Thanks!

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (WICKET-1143) Modify InjectorHolder to allow for storage of multiple types of Injectors (for Guice support)

Posted by "Damian Nowak (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-1143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12915011#action_12915011 ] 

Damian Nowak edited comment on WICKET-1143 at 9/26/10 2:17 PM:
---------------------------------------------------------------

I managed to create some almost-working Injector for both Java EE and Spring. EJBs and Spring Beans get injected with this.

Almost-working because I get serialization exceptions - I don't know why Wicket needs the class serializable as the classes from Java EE injector and Spring injector are not and they work. Problem appears with any @SpringBean declared in page class.

If anyone is able to correct it so that no serialization exceptions are thrown, feel free.

in Application.init():

{noformat}
addComponentInstantiationListener(new SpringComponentInjector(this));
addComponentInstantiationListener(new JavaEEComponentInjector(this, createNamingStrategy()));
final SpringAndJavaEeInjector springAndJavaEeInjector = new SpringAndJavaEeInjector(this, new StandardJndiNamingStrategy()); // I use my own naming strategy, StandardJndiNamingStrategy is the default
InjectorHolder.setInjector(springAndJavaEeInjector);
{noformat}

{noformat}
import java.io.Serializable;
import java.lang.reflect.Field;
import org.apache.wicket.IClusterable;
import org.apache.wicket.injection.ConfigurableInjector;
import org.apache.wicket.injection.IFieldValueFactory;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.spring.ISpringContextLocator;
import org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.wicketstuff.javaee.injection.JavaEEProxyFieldValueFactory;
import org.wicketstuff.javaee.naming.IJndiNamingStrategy;

public class SpringAndJavaEeInjector extends ConfigurableInjector implements Serializable {

	private final SpringAndJavaEeFieldValueFactory factory;

	public SpringAndJavaEeInjector(final WebApplication webApplication, final IJndiNamingStrategy namingStrategy) {
		JavaEEProxyFieldValueFactory javaEeFactory = new JavaEEProxyFieldValueFactory(namingStrategy);
		AnnotProxyFieldValueFactory springFactory = new AnnotProxyFieldValueFactory(new ISpringContextLocator() {

			@Override
			public ApplicationContext getSpringContext() {
				return WebApplicationContextUtils.getRequiredWebApplicationContext(webApplication.getServletContext());
			}
		}, true);
		factory = new SpringAndJavaEeFieldValueFactory(javaEeFactory, springFactory);
	}

	@Override
	protected IFieldValueFactory getFieldValueFactory() {
		return factory;
	}

	private static class SpringAndJavaEeFieldValueFactory implements IFieldValueFactory {

		private final JavaEEProxyFieldValueFactory javaEeFactory;

		private final AnnotProxyFieldValueFactory springFactory;

		public SpringAndJavaEeFieldValueFactory(JavaEEProxyFieldValueFactory javaEeFactory, AnnotProxyFieldValueFactory springFactory) {
			this.javaEeFactory = javaEeFactory;
			this.springFactory = springFactory;
		}

		@Override
		public Object getFieldValue(Field field, Object fieldOwner) {
			try {
				final Object fieldValue = javaEeFactory.getFieldValue(field, fieldOwner);
				if (fieldValue == null) {
					throw new RuntimeException();
				}
				return fieldValue;
			} catch (Exception e) {
				return springFactory.getFieldValue(field, fieldOwner);
			}
		}

		@Override
		public boolean supportsField(Field field) {
			final boolean supportsField = javaEeFactory.supportsField(field);
			if (supportsField) {
				return true;
			}
			return springFactory.supportsField(field);
		}
	}

}
{noformat}

Ehh, Wiki syntax is turned off here. Here is a formatted and highlighted code: http://wklej.org/id/393829/

      was (Author: nowaker):
    I managed to create some almost-working Injector for both Java EE and Spring. EJBs and Spring Beans get injected with this.

Almost-working because I get serialization exceptions - I don't know why Wicket needs the class serializable as the classes from Java EE injector and Spring injector are not and they work.

If anyone is able to correct it so that no serialization exceptions are thrown, feel free.

in Application.init():

{noformat}
addComponentInstantiationListener(new SpringComponentInjector(this));
addComponentInstantiationListener(new JavaEEComponentInjector(this, createNamingStrategy()));
final SpringAndJavaEeInjector springAndJavaEeInjector = new SpringAndJavaEeInjector(this, new StandardJndiNamingStrategy()); // I use my own naming strategy, StandardJndiNamingStrategy is the default
InjectorHolder.setInjector(springAndJavaEeInjector);
{noformat}

{noformat}
import java.io.Serializable;
import java.lang.reflect.Field;
import org.apache.wicket.IClusterable;
import org.apache.wicket.injection.ConfigurableInjector;
import org.apache.wicket.injection.IFieldValueFactory;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.spring.ISpringContextLocator;
import org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.wicketstuff.javaee.injection.JavaEEProxyFieldValueFactory;
import org.wicketstuff.javaee.naming.IJndiNamingStrategy;

public class SpringAndJavaEeInjector extends ConfigurableInjector implements Serializable {

	private final SpringAndJavaEeFieldValueFactory factory;

	public SpringAndJavaEeInjector(final WebApplication webApplication, final IJndiNamingStrategy namingStrategy) {
		JavaEEProxyFieldValueFactory javaEeFactory = new JavaEEProxyFieldValueFactory(namingStrategy);
		AnnotProxyFieldValueFactory springFactory = new AnnotProxyFieldValueFactory(new ISpringContextLocator() {

			@Override
			public ApplicationContext getSpringContext() {
				return WebApplicationContextUtils.getRequiredWebApplicationContext(webApplication.getServletContext());
			}
		}, true);
		factory = new SpringAndJavaEeFieldValueFactory(javaEeFactory, springFactory);
	}

	@Override
	protected IFieldValueFactory getFieldValueFactory() {
		return factory;
	}

	private static class SpringAndJavaEeFieldValueFactory implements IFieldValueFactory {

		private final JavaEEProxyFieldValueFactory javaEeFactory;

		private final AnnotProxyFieldValueFactory springFactory;

		public SpringAndJavaEeFieldValueFactory(JavaEEProxyFieldValueFactory javaEeFactory, AnnotProxyFieldValueFactory springFactory) {
			this.javaEeFactory = javaEeFactory;
			this.springFactory = springFactory;
		}

		@Override
		public Object getFieldValue(Field field, Object fieldOwner) {
			try {
				final Object fieldValue = javaEeFactory.getFieldValue(field, fieldOwner);
				if (fieldValue == null) {
					throw new RuntimeException();
				}
				return fieldValue;
			} catch (Exception e) {
				return springFactory.getFieldValue(field, fieldOwner);
			}
		}

		@Override
		public boolean supportsField(Field field) {
			final boolean supportsField = javaEeFactory.supportsField(field);
			if (supportsField) {
				return true;
			}
			return springFactory.supportsField(field);
		}
	}

}
{noformat}

Ehh, Wiki syntax is turned off here. Here is a formatted and highlighted code: http://wklej.org/id/393829/
  
> Modify InjectorHolder to allow for storage of multiple types of Injectors (for Guice support)
> ---------------------------------------------------------------------------------------------
>
>                 Key: WICKET-1143
>                 URL: https://issues.apache.org/jira/browse/WICKET-1143
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket, wicket-guice
>    Affects Versions: 1.3.0-beta4
>            Reporter: Peter Mularien
>            Assignee: Martin Grigorov
>
> As per discussion on the mailing list:
> http://www.nabble.com/Question-about-Guice-integration-with-Wicket-1.3-beta-4-tf4778901.html#a13672025
> InjectorHolder should play nicely with GuiceComponentInjector, and allow for mixed systems using both Spring and Guice. Thanks!

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (WICKET-1143) Modify InjectorHolder to allow for storage of multiple types of Injectors (for Guice support)

Posted by "Damian Nowak (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-1143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12915011#action_12915011 ] 

Damian Nowak edited comment on WICKET-1143 at 9/26/10 2:17 PM:
---------------------------------------------------------------

I managed to create some almost-working Injector for both Java EE and Spring. EJBs and Spring Beans get injected with this.

Almost-working because I get serialization exceptions - I don't know why Wicket needs the injector class serializable as the classes from Java EE injector and Spring injector are not and they work. Problem appears with any @SpringBean declared in page class.

If anyone is able to correct it so that no serialization exceptions are thrown, feel free.

in Application.init():

{noformat}
addComponentInstantiationListener(new SpringComponentInjector(this));
addComponentInstantiationListener(new JavaEEComponentInjector(this, createNamingStrategy()));
final SpringAndJavaEeInjector springAndJavaEeInjector = new SpringAndJavaEeInjector(this, new StandardJndiNamingStrategy()); // I use my own naming strategy, StandardJndiNamingStrategy is the default
InjectorHolder.setInjector(springAndJavaEeInjector);
{noformat}

{noformat}
import java.io.Serializable;
import java.lang.reflect.Field;
import org.apache.wicket.IClusterable;
import org.apache.wicket.injection.ConfigurableInjector;
import org.apache.wicket.injection.IFieldValueFactory;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.spring.ISpringContextLocator;
import org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.wicketstuff.javaee.injection.JavaEEProxyFieldValueFactory;
import org.wicketstuff.javaee.naming.IJndiNamingStrategy;

public class SpringAndJavaEeInjector extends ConfigurableInjector implements Serializable {

	private final SpringAndJavaEeFieldValueFactory factory;

	public SpringAndJavaEeInjector(final WebApplication webApplication, final IJndiNamingStrategy namingStrategy) {
		JavaEEProxyFieldValueFactory javaEeFactory = new JavaEEProxyFieldValueFactory(namingStrategy);
		AnnotProxyFieldValueFactory springFactory = new AnnotProxyFieldValueFactory(new ISpringContextLocator() {

			@Override
			public ApplicationContext getSpringContext() {
				return WebApplicationContextUtils.getRequiredWebApplicationContext(webApplication.getServletContext());
			}
		}, true);
		factory = new SpringAndJavaEeFieldValueFactory(javaEeFactory, springFactory);
	}

	@Override
	protected IFieldValueFactory getFieldValueFactory() {
		return factory;
	}

	private static class SpringAndJavaEeFieldValueFactory implements IFieldValueFactory {

		private final JavaEEProxyFieldValueFactory javaEeFactory;

		private final AnnotProxyFieldValueFactory springFactory;

		public SpringAndJavaEeFieldValueFactory(JavaEEProxyFieldValueFactory javaEeFactory, AnnotProxyFieldValueFactory springFactory) {
			this.javaEeFactory = javaEeFactory;
			this.springFactory = springFactory;
		}

		@Override
		public Object getFieldValue(Field field, Object fieldOwner) {
			try {
				final Object fieldValue = javaEeFactory.getFieldValue(field, fieldOwner);
				if (fieldValue == null) {
					throw new RuntimeException();
				}
				return fieldValue;
			} catch (Exception e) {
				return springFactory.getFieldValue(field, fieldOwner);
			}
		}

		@Override
		public boolean supportsField(Field field) {
			final boolean supportsField = javaEeFactory.supportsField(field);
			if (supportsField) {
				return true;
			}
			return springFactory.supportsField(field);
		}
	}

}
{noformat}

Ehh, Wiki syntax is turned off here. Here is a formatted and highlighted code: http://wklej.org/id/393829/

      was (Author: nowaker):
    I managed to create some almost-working Injector for both Java EE and Spring. EJBs and Spring Beans get injected with this.

Almost-working because I get serialization exceptions - I don't know why Wicket needs the class serializable as the classes from Java EE injector and Spring injector are not and they work. Problem appears with any @SpringBean declared in page class.

If anyone is able to correct it so that no serialization exceptions are thrown, feel free.

in Application.init():

{noformat}
addComponentInstantiationListener(new SpringComponentInjector(this));
addComponentInstantiationListener(new JavaEEComponentInjector(this, createNamingStrategy()));
final SpringAndJavaEeInjector springAndJavaEeInjector = new SpringAndJavaEeInjector(this, new StandardJndiNamingStrategy()); // I use my own naming strategy, StandardJndiNamingStrategy is the default
InjectorHolder.setInjector(springAndJavaEeInjector);
{noformat}

{noformat}
import java.io.Serializable;
import java.lang.reflect.Field;
import org.apache.wicket.IClusterable;
import org.apache.wicket.injection.ConfigurableInjector;
import org.apache.wicket.injection.IFieldValueFactory;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.spring.ISpringContextLocator;
import org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.wicketstuff.javaee.injection.JavaEEProxyFieldValueFactory;
import org.wicketstuff.javaee.naming.IJndiNamingStrategy;

public class SpringAndJavaEeInjector extends ConfigurableInjector implements Serializable {

	private final SpringAndJavaEeFieldValueFactory factory;

	public SpringAndJavaEeInjector(final WebApplication webApplication, final IJndiNamingStrategy namingStrategy) {
		JavaEEProxyFieldValueFactory javaEeFactory = new JavaEEProxyFieldValueFactory(namingStrategy);
		AnnotProxyFieldValueFactory springFactory = new AnnotProxyFieldValueFactory(new ISpringContextLocator() {

			@Override
			public ApplicationContext getSpringContext() {
				return WebApplicationContextUtils.getRequiredWebApplicationContext(webApplication.getServletContext());
			}
		}, true);
		factory = new SpringAndJavaEeFieldValueFactory(javaEeFactory, springFactory);
	}

	@Override
	protected IFieldValueFactory getFieldValueFactory() {
		return factory;
	}

	private static class SpringAndJavaEeFieldValueFactory implements IFieldValueFactory {

		private final JavaEEProxyFieldValueFactory javaEeFactory;

		private final AnnotProxyFieldValueFactory springFactory;

		public SpringAndJavaEeFieldValueFactory(JavaEEProxyFieldValueFactory javaEeFactory, AnnotProxyFieldValueFactory springFactory) {
			this.javaEeFactory = javaEeFactory;
			this.springFactory = springFactory;
		}

		@Override
		public Object getFieldValue(Field field, Object fieldOwner) {
			try {
				final Object fieldValue = javaEeFactory.getFieldValue(field, fieldOwner);
				if (fieldValue == null) {
					throw new RuntimeException();
				}
				return fieldValue;
			} catch (Exception e) {
				return springFactory.getFieldValue(field, fieldOwner);
			}
		}

		@Override
		public boolean supportsField(Field field) {
			final boolean supportsField = javaEeFactory.supportsField(field);
			if (supportsField) {
				return true;
			}
			return springFactory.supportsField(field);
		}
	}

}
{noformat}

Ehh, Wiki syntax is turned off here. Here is a formatted and highlighted code: http://wklej.org/id/393829/
  
> Modify InjectorHolder to allow for storage of multiple types of Injectors (for Guice support)
> ---------------------------------------------------------------------------------------------
>
>                 Key: WICKET-1143
>                 URL: https://issues.apache.org/jira/browse/WICKET-1143
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket, wicket-guice
>    Affects Versions: 1.3.0-beta4
>            Reporter: Peter Mularien
>            Assignee: Martin Grigorov
>
> As per discussion on the mailing list:
> http://www.nabble.com/Question-about-Guice-integration-with-Wicket-1.3-beta-4-tf4778901.html#a13672025
> InjectorHolder should play nicely with GuiceComponentInjector, and allow for mixed systems using both Spring and Guice. Thanks!

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (WICKET-1143) Modify InjectorHolder to allow for storage of multiple types of Injectors (for Guice support)

Posted by "Martin Grigorov (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-1143?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Martin Grigorov reassigned WICKET-1143:
---------------------------------------

    Assignee: Martin Grigorov  (was: Alastair Maw)

> Modify InjectorHolder to allow for storage of multiple types of Injectors (for Guice support)
> ---------------------------------------------------------------------------------------------
>
>                 Key: WICKET-1143
>                 URL: https://issues.apache.org/jira/browse/WICKET-1143
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket, wicket-guice
>    Affects Versions: 1.3.0-beta4
>            Reporter: Peter Mularien
>            Assignee: Martin Grigorov
>
> As per discussion on the mailing list:
> http://www.nabble.com/Question-about-Guice-integration-with-Wicket-1.3-beta-4-tf4778901.html#a13672025
> InjectorHolder should play nicely with GuiceComponentInjector, and allow for mixed systems using both Spring and Guice. Thanks!

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-1143) Modify InjectorHolder to allow for storage of multiple types of Injectors (for Guice support)

Posted by "Martin Grigorov (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-1143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12894911#action_12894911 ] 

Martin Grigorov commented on WICKET-1143:
-----------------------------------------

Do we still want this feature ?
I don't remember anyone ever asked in mailing lists/irc about this feature.
The idea explained by Al in the mail thread looks feasible for 1.5 and I can add it, but do we want it ?

> Modify InjectorHolder to allow for storage of multiple types of Injectors (for Guice support)
> ---------------------------------------------------------------------------------------------
>
>                 Key: WICKET-1143
>                 URL: https://issues.apache.org/jira/browse/WICKET-1143
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket, wicket-guice
>    Affects Versions: 1.3.0-beta4
>            Reporter: Peter Mularien
>            Assignee: Alastair Maw
>
> As per discussion on the mailing list:
> http://www.nabble.com/Question-about-Guice-integration-with-Wicket-1.3-beta-4-tf4778901.html#a13672025
> InjectorHolder should play nicely with GuiceComponentInjector, and allow for mixed systems using both Spring and Guice. Thanks!

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.