[
https://issues.apache.org/jira/browse/WICKET-2476?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12758576#action_12758576
]
Igor Vaynberg commented on WICKET-2476:
---------------------------------------
there is too many things in the original description...
lets break things down into two categories based on the injection semantics
that spring defines
a) session/request cope
b) prototype
usecase (a) is handled by spring via a proxy. you get an instance of your bean
but that instance is a proxy that delegates to actual bean instances based on
scope. so it doesnt matter if wicket holds on to the same "instance" of your
request-scoped bean across requests, because spring will handle that behind the
scenes.
so session and request scoped beans should work just fine in wicket. please
create a quickstart that demonstrates this is not so.
usecase (b) the semantic of a "prototype" scope is defined by "new instance
whenever it is requested from the container". what is the prototype scope when
mapped to wicket then? it is on the initial instantiation of the component, and
on subsequent deserializations.
if you are resetting your bean on every beforerender then sounds like you
should be using request-scoped beans. just make sure everything in your context
is properly configured, eg the injected instance is a spring-managed scope
proxy.
> 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
>
> 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.