I have used ExecuAndWait
in Struts2
I am getting error NPE
while setting attribute in request in action(which is long running)
I had a similar problem with execAndWait
interceptor throwing NPE
. You can find my case study here: execAndWait interceptor not working with validation on how I solved this problem.. In this problem what I find out was, that execAndWait
runs in separate thread and keeps throwing wait
until action is completed and in mean time it cycles itself. I faced this problem, because I used model driven
interceptor with it. Due to that the getModel()
of model driven interceptor was repeatedly being called by execAndWait
interceptor. In getModel method, it was setting the new POJO object again and again from scratch.
And then it was entering into validate
method for validation. Inside validation process it found one of the POJO field to be null. Obviously, it happened due to re-creating of raw new POJO object in getModel
. And thus was throwing Null Pointer Exception
.
So what I did was I used SessionAware
interface. And stored the POJO object for the first time when it entered validate
. Because execAndWait
will surely call all methods again and re-write an object from scratch. For this purpose I checked the availability of that object in getModel()
method. If that found in session, then return that same object, rather of creating a new object.
I hope you'll find a way from this.