user3653546
user3653546

Reputation: 31

struts2 value stack implementation

How does value stack work internally in Struts2 or when object on value stack is created, is it before interceptors execution or after interceptors execution? And how getters and setters called by interceptors when an object is pushed on value stack?

Upvotes: 1

Views: 96

Answers (1)

Dave Newton
Dave Newton

Reputation: 160321

The code is available, and it's the best explanation I've seen.

  1. Objects get either (a) pushed onto the stack, or (b) put into the value stack context. The former are accessed through normal OGNL notation. The latter are accessed through OGNL's # prefix character, which basically means "this is a named value in the value stack context".
  2. First the context's stack is created. Anything down the line may modify the value stack (and its context); interceptors and actions being the obvious main actors.
  3. Interceptors don't normally do much with the value stack other than possible push objects onto it. Getters and setters are on actions, not the stack, and they're generally called directly.
  4. When you access the value stack using OGNL it evaluates the OGNL expression against the value stack. Named values go against the context, everything else goes against the stack. If the "current" stack level doesn't resolve to a value then the next stack level is queried, and so on until there's no more stack elements left.

Upvotes: 3

Related Questions