• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

Struts 2 - Passing object in the hidden value

 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to assign an object(DTO) to a hidden variable in Struts 2?

I tried doing the following:

<s:hidden value="%{addressDTO}" name="address" />

However, it fails throwing following exception:

Cannot create type class com.abc.dto.AddressDTO from value com.abc.dto.AddressDTO@c86b31 - [unknown location]
at com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter.convertValue(XWorkBasicConverter.java:126)
at com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter.convertValue(XWorkBasicConverter.java:120)
at com.opensymphony.xwork2.conversion.impl.XWorkConverter.convertValue(XWorkConverter.java:328)

2013-07-04 18:35:16 WARN OgnlValueStack:64 - Error setting expression 'address' with value '[Ljava.lang.String;@198d24d'
ognl.MethodFailedException: Method "setAddress" failed for object com.abc.action.InitiateOrderAction@1d1ca96 [java.lang.NoSuchMethodException: com.abc.action.InitiateOrderAction.setAddress([Ljava.lang.String;)]
at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1305)
at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:1494)


Looking at the above exception it seems that only string values can be assigned to a hidden variable. I was assuming objects can also be assigned to a hidden variable ?

Any thoughts ?

Saurabh
 
Bartender
Posts: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Saurabh Agrawal wrote:
Looking at the above exception it seems that only string values can be assigned to a hidden variable.



Correct. You are limited to what HTML supports. If you wanted to get fancy, you could probably create a JSON type converter and save the JSON string to the hidden field.
 
This cake looks terrible, but it tastes great! Now take a bite out of this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic