[
https://issues.apache.org/jira/browse/WICKET-2476?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12758891#action_12758891
]
Dominik Drzewiecki commented on WICKET-2476:
--------------------------------------------
In my particular case I've been using a factory bean that returned differently
scoped instances of Strings, which as I learned later, are treated quite
differently along with the rest of primitives due to the inability to generate
proxy for final types. Injector injects raw values for primitives rather than
proxies then. This made my piece of code behave odd. I've rewritten the app to
use the class that encapsulates the String, just for the sole purpose of the
proxies to be generated. I still do not feel comfy with with how it behaves
(but maybe I'm missing something) - when page model changes, nothing happens to
the values that are retrieved from request or prototype scoped beans.
Quickstart to follow shortly
> SpringBean annotated fields are not reinjected when the same instance of the
> component is being reused.
> -------------------------------------------------------------------------------------------------------
>
> Key: WICKET-2476
> URL: https://issues.apache.org/jira/browse/WICKET-2476
> Project: Wicket
> Issue Type: Improvement
> Components: wicket-spring
> Affects Versions: 1.4.1
> Reporter: Dominik Drzewiecki
> Assignee: Igor Vaynberg
>
> SpringBean annotated components' fields get injected on instantiation only
> (well, that's when the IComponentInstantiationListener implementations are
> supposed kick in), while they are left as-is on subsequent reusage of the
> same component (e.g. when Page instance is retrieved from the pageMap rather
> than being instantiated). This behavior leads to the wrong instances of beans
> being available as reused components injected fields whenever the scope of
> the bean is declared as "prototype" or "request" (or some other scope
> narrower than "session"). A glimpse at the wicket guts led me to the
> hypothesis that this problem might be solved by additionally implementing
> IComponentOnBeforeRenderListener and registering it using
> addPreComponentOnBeforeRenderListener(). How about:
> package org.apache.wicket.injection;
> public class ComponentInjector implements IComponentInstantiationListener,
> IComponentOnBeforeRenderListener
> {
> public void onInstantiation(Component component) {
> getInjector().inject(component);
> }
> .....
> public void onBeforeRender(Component component) {
> getInjector().inject(component);
> }
> }
> and then in Application's init()
> ComponentInjector injector = new SpringComponentInjector(this);
> addComponentInstantiationListener(injector);
> addPreComponentOnBeforeRenderListener(injector);
> My initial observations prove that the injector.inject() should also
> correctly address the case whenever the instance had already been injected
> with the proxy (otherwise field.get(object) call fails)
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.