File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts2 that acts as a ServletContextListener

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

I would like to ask if there is a class in Struts2.1.6 that acts like a ServletContextListener? The reason why I'm trying to do this is I do have a values that would be fetched in the DB and I want it available in my entire application.

Another thing, if there is really a class for my question, how would I put it in my page(application scope)?

Thanks,
Paul
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Normally you'd just implement a ServletContextListener.
 
Paul Michael Serrano
Ranch Hand
Posts: 59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could I have a class that extends ActionSupport and at the same time implements a ServletContextListener and ApplicationAware interfaces?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course, but that doesn't necessarily mean it'll work the way you think it will, but you don't really state what you're trying to accomplish, so it's hard to say. If you're trying to get the benefits of Spring integration, for example, it probably won't work--the container instantiates servlet context listeners, not Spring.

If you're trying to use Spring-oriented stuff there's an event interface you can implement then check for an application context startup message.

What are you trying to do?
 
Paul Michael Serrano
Ranch Hand
Posts: 59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We are currently working on Struts2 framework only with version 2.1.6, we are not integrating it with Spring.

All I want to do, is to have a visibility of my ArrayList in my whole application. So I'm trying to do it like this...


I also put this snippet of code in my JSP, just to check if I'm getting it in my page. But unfortunately application.languageList is always null eventhough I've commented the DBconnection and force to put values in my ArrayList.

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why does this need to be an action?
 
Paul Michael Serrano
Ranch Hand
Posts: 59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if I'm right. I tried extending ActionSupport just to be sure that I could have a value in my ApplicationAware. But still, I'm failing to get the value that I've set here....

testMap.put("languageList", languageList);
this.setApplication(testMap);


Thanks,
-Paul
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're not saving anything to the application map, you're creating a *new* map and putting the value in that. Then you call the action's setter, and overwrite the reference to the actual application map.

I still don't understand why this needs to be an action if you're not doing anything related to Struts 2.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic