IntelliJ Java IDE
The moose likes Struts and the fly likes NPE when trying to access a list from action class Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Application Frameworks » Struts
Reply Bookmark "NPE when trying to access a list from action class" Watch "NPE when trying to access a list from action class" New topic
Author

NPE when trying to access a list from action class

Dan Rasmussen
Greenhorn

Joined: Feb 10, 2012
Posts: 2

I spent a couple of years with Struts 1 back in the day (2003 - 2005 or so). Just coming back to it again and have a maddening (but familiar feeling problem). Basically, I have a list that I am populating and mutating through a single jsp page that calls out separate actions depending on user actions (init() on entry, addFieldMapping() to add to the list, etc.). The init() properly initializes the list and it displays just fine when I get there but when I get to the addField, the list is null. I believe I have all the relevant code listed below. I suspect it has something to do with my jsp where I print out the list and ready it to be loaded back into the action class or something to do with validate() but I dumped the validate() method (not implemented).

My struts.xml has these entries:



I have a list in my action clss like so:



My jsp properly displays the test data populated in the init() but, when the addFieldMapping action is exercised, fmList is NULL in the addField() method.

I have been beating my head against this for hours, including changing approaches (started with a Map). Why is fmList not getting populated from my jsp? I have tried many flavors of the s:label line including:



and



Here is the last incantation of it:




Help! Thanks in advance.
Dan Rasmussen
Greenhorn

Joined: Feb 10, 2012
Posts: 2

OK. I have made a little bit of progress by looking at the page source in the browser and adding debug so that I could see when the setter was being called for fmList. The NPE is gone but the setter for the list is being called with an empty list. Please read on..

The first two problems I noticed was that the field name/id was not being properly generated. Second, I noticed that the setter was not being called for fmList. I figued that the setter wasn't being called because I was using an s:label, so I changed it to a text. Then I fooled around with the jsp to get the name/id properly populated. The resulting jsp for this field is:



which produces html like this:


etc.

So now my setter is being called but the list being passed in is empty. Any suggestions?

Thanks,

Dan

 
 
subject: NPE when trying to access a list from action class
 
Threads others viewed
How to retain automatically generated fields on pageload in struts2
Update Database with the newly entered value
data lost from JSP back to same Action (struts 2)
Equivalent of logic iterate in Struts 2
Problem of resubmisson in struts2
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com