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-
We know that
params
interceptor moves the data from the request parameters to the action object inValueStack
. Now while reading, I came upon a line that says- "The tricky part of the job is mapping the name of the parameter to an actual property on theValueStack
. This is where OGNL comes in. Theparams
interceptor interprets the request parameter name as an OGNL expression to locate the correct destination property on the ValueStack".Question 1) Here, what does "interprets" mean? Is it that params interceptor translates the request parameter into some OGNL expression and then OGNL expression provides mapping to the properties in ValueStack OR does it mean something else?
When result start its rendering process, the Struts 2 tags retrieve data from the ValueStack by referencing specific values with OGNL expressions.
Question 2) So the tags take OGNL expressions, but how is the data being moved? Earlier,
params
interceptor was the one that moved the data but now there is noparams
interceptor. So how is the data being moved?
Let us say you write Login page and corresponding Login Action. On page you have a text box which has a name that says that it is a name field of User object. You also have a password field on page that says it maps to pwd field on the User object.
Now Object graph here would mean that it has to tell the params interceptor that the name field is actually a name field of user object in the login action. The action context, valuestack and OGNL will together have the knowledge that: Well maybe there are other actions as well, like FileUploadAction. And these other actions may also have a user object reference. But for current action context, the name field from the login page actually maps to nothing else but the name field of Login Action's user object. It does not belong to the name field of user object of FileUploadAction. They have this knowledge and also behave as if the field itself (actually the entire object graph) sits on value stack and is directly accessible. (A little background on ThreadLocal will be better to understand this.)
The interceptors are chained and it becomes a chain of responsibility on the way forward and back. An interceptor may perform some action is forward direction or the return direction or both. So let us say the the flow is like below:
Then the return flow would be like below:
So, to answer your question, params inteceptor will be called in the return flow as well.