File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Struts2 - How to save an object through ApplicationAware. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 - How to save an object through ApplicationAware." Watch "Struts2 - How to save an object through ApplicationAware." New topic
Author

Struts2 - How to save an object through ApplicationAware.

Paul Michael Serrano
Ranch Hand

Joined: Nov 22, 2004
Posts: 59
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

Joined: Aug 03, 2008
Posts: 9280
    
  17

Why are you using ApplicationAware for this?? Just create a ServletContextListener and put the attribute in the ServletContext object...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Ankit is correct. ApplicationAware is meaningless outside of a Struts 2 interceptor stack.
Paul Michael Serrano
Ranch Hand

Joined: Nov 22, 2004
Posts: 59
Thanks David and Ankit. I got it working now using the ServletContext object, and could see the value in my JSP.




Paul
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts2 - How to save an object through ApplicationAware.
 
Similar Threads
listener tag is not working in Tomcat
When HttpSessionAttributeListener and HttpSessionBindingListener methods are called?
Calling Servlet method from Bean
Getting Database Connection from Servlet
Struts2 that acts as a ServletContextListener