M Sach
M Sach

Reputation: 34424

Some Questions about valuestack in struts2 and stack?

I am new to struts2 and going thru struts2 in action where i came across the statement that says valuestack is the stack of object and statements where it discuss how resolution takes place when two objects having same property names are stored on value object. To clear this,I started looking into how it is implemented in struts2. When i went to last level , i found struts2 simply inserting the object at zero position inside push method similarly during peek, it gets the object from zero postion. So as per my understanding under struts2, value stack is going to contain only one object (and that will be action object). Is that correct? If it is not correct when can we have scenario where we can store more than a object in valuestack apart from action object?

Also i came up about some fundamental question about stack when i went thru stack at http://en.wikipedia.org/wiki/Stack_(abstract_data_type). It is stated there that In computer science, a stack is a last in, first out (LIFO) abstract data type and linear data structure and characterized by two fundamental operations, called push and pop . I agree that datastructure that involves push and pop operation classifies for stack. But got doubt about LIFO stuff.When i see array implementation in java(which is also stack and stated at the same link), as per my understanding it does not follow the LIFO as we can access any element thru index not necesseraly last element has to come out. Dont flame me if am wrong as this is the notation i have. If this correct can we say stack does not have to be compulsory LIFO only it should confirm push and pop operation?

Upvotes: 0

Views: 682

Answers (1)

Dave Newton
Dave Newton

Reputation: 160321

No, the value stack will not contain a single object under almost all circumstances, and it wouldn't be much of a stack if it only allowed a single object.

When you insert an object at position 0, it's a push--the object previously as position 0 will then be at position 1, etc. It's a normal push, using the insert method.

Essentially all normal action invocations will have multiple objects on the stack. This is trivially demonstrable using either the <s:debug> tag (image below), or by dumping the stack. In addition, the <s:push> tag will add objects to the stack on a JSP page, interceptors can add objects, etc.

Your observation about stacks being LIFO is interesting, but ultimately irrelevant: normal stack operations (push, pop) are what make it LIFO. This doesn't preclude a stack implementation from offering additional access modes.


debug tag value stack dump

Upvotes: 6

Related Questions