-
Notifications
You must be signed in to change notification settings - Fork 811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WW-4827 Not fully initialized ObjectFactory tries to create beans #153
Conversation
No better idea and I think we can assume when you need to inject the |
To keep protected Object injectInternalBeans(Object obj) {
if (obj != null) {
if(container != null) container.inject(obj);
else myPrivateInjectQueue.add(obj);
}
return obj;
}
@Inject
public void setContainer(Container container) {
this.container = container;
if(null != this.container && myPrivateInjectQueue.getCount()>0)
{
foreach(Object obj in myPrivateInjectQueue) this.container.inject(obj);
myPrivateInjectQueue.clear();
}
} However I never tried and tested it but you can if you think it makes sense. |
I'm not sure if this is a good idea ... basically we need a |
Hm... give me few minutes, maybe I will be able add support for it ;-) |
I have opened #155 - what do you think? @aleksandr-m can you test it locally as I do not have the exact setup. |
Nope, #155 doesn't seem have any effect. Add following files to project, run under *nix, execute some action which leads to the JSP, xwork-conversion.properties;
JSP:
DateConverter:
|
hm... but this example works for both branches -
|
(on OSX) |
One more question: JDK version? |
Ubuntu, oracle jdk8. If following code prints
|
See these screenshots masterthis branchas you see, on the Maybe you have discovered another place where there is some work done in setter which should be moved into the |
It isn't about BTW |
... but where the |
I have changed code a bit, can you try to test it on your side? |
With the new code in #155 the custom type converter isn't initialized at all. :( With previous code in #155 the call trace of DateConverter is:
|
w00t! |
Would it be possible to share an application that replicates this behaviour? Sorry for bothering you but I want to understand what's going on :) |
I don't see any other options now to merge this. @aleksandr-m could you prepare that example app? I will be able to investigate what's wrong with my solution ;-) |
Sure. No problem. Test project - https://github.com/aleksandr-m/struts2-objectfactory-container/ This commit adds custom date converter - aleksandr-m/struts2-objectfactory-container@49406c1. This commit adds local copy of |
Thanks a lot :) I see now what's going on but have no idea why :\ |
@aleksandr-m , I modified ...
private List<Object> myPrivateInjectQueue;
...
@Inject
public void setContainer(Container container) {
this.container = container;
if(null != this.container && null!=myPrivateInjectQueue && myPrivateInjectQueue.size()>0)
{
for(Object obj : myPrivateInjectQueue) this.container.inject(obj);
myPrivateInjectQueue.clear();
myPrivateInjectQueue=null;
}
}
...
protected Object injectInternalBeans(Object obj) {
if (obj != null) {
if(container != null) container.inject(obj);
else {
if(null==myPrivateInjectQueue)myPrivateInjectQueue=new ArrayList<Object>();
myPrivateInjectQueue.add(obj);}
}
return obj;
} in your sample I got following ok result :)
|
@yasserzamani Looks like a hack :) I would rather leave as it is, then to introduce that. If container is needed then it should be injected in the constructor. Take a look at spring object factory. |
:) Yes I know, just a bit worry about backward compatibility between minor versions. I also am studying your sample and @lukaszlenart 's pr to understand what is going on as I think same issues may exist because it seems an object's injections is not an atomic operations! shouldn't be? |
@lukaszlenart , as I debug, the trace is As you see, if you would like to make it works, the processRequired("struts-default-conversion.properties");
process("xwork-conversion.properties"); |
The case is that on second container initialisation we do not create singletons upfront ... I have tried to change that but got some problems, not sure why. I must re-think how we initialise Struts internals ... |
Inject
Container
in constructor of theObjectFactory
.Can someone test
cdi
,osgi
andplexus
plugins.Better ideas how to fix the issue are welcome. :)