I am new to Struts 2. I am studying it from the book Struts2 In Action. I am having difficulty in understanding some concepts in OGNL which are as follows-
Answer #1
The parameter names ARE OGNL expressions. It's a case of ConventionOverConfiguraiton. If we agree to make the names of the parameters valid OGNL expressions that can access a javabeans property, then it's easy to simply hand that name over to OGNL as an expression. This is done internally of course; you don't really need to know how it works unless you are hacking on that part of the Struts 2 code.
Answer #2
The action object is sitting on top of the ValueStack. The ValueStack is avaible, via it's existence as part of the ThreadLocal ActionContext, from any code executing on the same thread. Since a web app uses a single thread to handle the processing of a request, we know that the Result layer will be able to get to the ValueStack to retrieve the data, again going using the name in the tag as a OGNL expression.
Note:
The key part of all of this is the fact that the ValueStack is available to any code executing on the same thread. This allows all code processing a single request to have access to the ValueStack, which they can obtain via the ThreadLocal ActionContext ( read about Java's ThreadLocal class if you don't understand ).
The params interceptor can then try to use the param name as an OGNL expression to write data to the ValueStack ( which servers as the OGNL context -- again read about the OGNL API if you don't understand ). Then the code in the Result classes that handle the rendering of the response can interpret the various names and values from the tag libraries as OGNL expressions to READ data from the ValueStack.