Struts2 ExecAndWait NullPointerException

后端 未结 1 1792
灰色年华
灰色年华 2021-01-27 20:32

I have used ExecuAndWait in Struts2

I am getting error NPE while setting attribute in request in action(which is long running)

相关标签:
1条回答
  • 2021-01-27 20:55

    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.

    0 讨论(0)
提交回复
热议问题