Reputation: 11
Can I keep an object reference in a hidden field in Struts 2?
My JSP:
<s:hidden name="employee"/>
The employee
is a reference, which refer an employee object in the Action
class, which invokes above JSP file.
Upvotes: -1
Views: 2198
Reputation: 1
When s:hidden
tag is rendered it put the value in the value
attribute after evaluating OGNL expression in the name
attribute.
Struts2 support basic type conversions for types other than String
. It has also support for writing custom converters for types it doesn't know as basic, but configured via XML.
So, you can create a new object for the type you reference in the name
attribute. But the value is not the object reference, it is the result of the OGNL expression evaluation, and if it is an Object
then toString()
method is called to get the value.
You may try to pass that string value to server and instantiate an object that will not have the same reference but might have the same hash code.
Upvotes: 1
Reputation: 715
No You can't transfer object using s:hidden name="employee", all the parameter, what are transferred with HTTP should be string. You can send object id else and retrieve object later.
or You can put your object into session, so that you can access it anytime you want. here is an example::
http://www.java4s.com/struts-tutorials/example-on-struts-2-sessionaware-interface/
Upvotes: 2