Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts2 - How to save an object through ApplicationAware.

 
Paul Michael Serrano
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I would like to ask if there is a possibility that I could save my objects using the ApplicationAware upon startup of my server by not using it as an action class?

My follow question is, could I implement ApplicationAware together with ServletContextListener so that I could have it saved upon startup of server?

I've tried creating a class like this one, but application.put("languageList", languageList); gives me NullPointerException everytime I start the tomcat.



web.xml snippet


I just need the object languageList to put it in <s:select> tag.

Thanks,
Paul
 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using ApplicationAware for this?? Just create a ServletContextListener and put the attribute in the ServletContext object...
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit is correct. ApplicationAware is meaningless outside of a Struts 2 interceptor stack.
 
Paul Michael Serrano
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks David and Ankit. I got it working now using the ServletContext object, and could see the value in my JSP.




Paul
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic