Reputation: 1
I understand ValueStack
was introduced in Struts 2, and one more change from Struts 1 model, there is now a new Action
object is instantiated for each request. So we can define instance variables without worrying about multi threading issues.
The way, interceptors and JSPs accessing the instance variables of the Action
objects, is through the ValueStack
. But, is there a way the ValueStack
is implemented (or at least used by Struts 2 framework), by using ValueStack.<variable>
, to make the access easier, so that we don't need to traverse the whole object tree?
I have following questions:
What if I have embedded objects (multiple hierarchy of objects)? How does the access mechanism behave in such a case?
If let us say 2 clients made requests to the same action at the same time, and the results of Action
execution are different, because the inputs provided by 2 clients came back with 2 different results. Let us say my Action
class has a method to get best price, and based on the logic in my backend service, the results come out as 10 and 12 for 2 different requests. Now Action
class has a member variable called price
, in which this value will be stored and the resultant JSP showResults.jsp
will access this variable (using a taglib) to show the price. How does Struts 2 framework guarantee that Client 1 and Client 2 get the right response back, and prices are not jumbled, while the response is shown on the JSP, because from what I understand, the ValueStack
just goes in first in first out (stack logic) fashion. So it might possibly end up returning 10 to both client requests as the same variable is stored twice (with the same name) on the value stack, but with different values.
When does the ValueStack
destroy the object from its list?
Upvotes: 0
Views: 1840
Reputation: 1
Embedded objects or in other words nested beans are accessed directly via their accessors or via OGNL that used that accessors when evaluating OGNL expression. Struts2 places an action bean on the top
of the valueStack
, so the action properties are retrieved by name, but nested beans are resolved using OGNL dot notation. More about OGNL you can find in the documentation .
Each action instance has it's own context and valueStack
, so the clients do not interfere with each other and have its own values unless the values are maintained in the application
scope.
The valueStack
is created by the dispatcher and put to the action context. It also could be recreated by some interceptors when needed. You should not worry about its values because they are destroyed at the action end.
Upvotes: 3