Amol Ghotankar
Amol Ghotankar

Reputation: 2094

Issue: Action redirect do not include parameter as complex objects in Struts2?

I have tried an example in which i have inserted a user using insert method of UserAction class.

On insert I have redirected the success to loadAdd method of UserAction.

During redirect I have passed the parameter as

${user}

In struts 2.0.14 this gives an ognl exception.

whereas when I pass

${user.id}

it works.

My observation says this is a bug in struts or ognl that it does parse composite objects while it parses simple data types.

Any work-around please suggest.

Or

Is there any way by which I can forward the complete action context or value stack in the redirected action

Upvotes: 0

Views: 1540

Answers (1)

Steven Benitez
Steven Benitez

Reputation: 11055

It's not a bug.

Struts2 uses a type conversion system to convert between Strings (native HTTP) and other objects. It has default type converters for all of the standard primitives, boxed primitives, collections, maps, etc. If you want to allow Struts2 to automatically convert between a string and your User class, you need to create a type converter for it. Otherwise, you can use ${user.id}, which is a primitive or boxed primitive.

http://struts.apache.org/2.2.3/docs/type-conversion.html

Also, the ValueStack is per-request, so when you redirect and create a new request, the previous requests ValueStack is no longer available.

Upvotes: 2

Related Questions