Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ActionError problems with Singleton Action Bean in Struts2

 
Konstantin Netkachev
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have problems with ActionErrors at Struts2.

Action I use is declared as singleton (by default).



And here is my action it struts.xml:



In "sell" method I add errors by addActionError and I'm getting into page with error message, it works good.
But when I (on this page with error) click any link to other action, I don't hit this action. Instead of it I receive message:

"No result defined for action action.ShipList and result input"
"The requested resource (No result defined for action action.ShipList and result input) is not available."


For example, I'm clicking a link on the page with errormessage.

Here is a link:



And here is an Action:



I set a brakepoint in the myShips method, but don't reach it.
Instead I receive that errormessages.

So what should I do to overcome this problem?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use singleton actions.

The framework is designed around using action-per-request.
 
Konstantin Netkachev
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But this Action contains ArrayList, which is initialized once by reading Database.
I don't want to init this list again every time I hit this Action. That's why I use Singleton.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Besides there being other ways to deal with that issue, what I'm telling you is fundamentally correct: S2 is designed to use an action-per-request.

If you work against that design principle you will have to work around the framework--an approach I don't recommend.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic