开发者

Using OGNL to return data from a Map<String,Object>

开发者 https://www.devze.com 2022-12-20 07:00 出处:网络
Using Struts 2.1.6, xwork 2.1.2 and ognl 2.6.11 In my struts action I have a Map that I am fetching elements from using OGNL. If the key I am using to fetch with does not exist in the map then OGNL re

Using Struts 2.1.6, xwork 2.1.2 and ognl 2.6.11 In my struts action I have a Map that I am fetching elements from using OGNL. If the key I am using to fetch with does not exist in the map then OGNL returns an empty object array, that OGNL converts to 开发者_如何转开发a string and I get the object reference java.lang.Object@6.... This occurs in several places and seems to be the the map having the value generic specified as an Object. This is not something I can change. I have traced the problem for a while, but when I ended up deep into the guts of the OGNL code and I did not see a light at the end of the tunnel. Currently I am going to go with an ugly hack of checking the string return to see if it starts with "java.lang.Object@" and if so return an empty string. I don't like the solution but thats what time permits. Has anyone encountered a similar problem?

Also, where did OpenSymphony go? updates to their webiste appear to have dried up, the user forums say they are being converted to Google Groups no later than Nov-12-09


This is a problem with null values: if value is null, default behavior is to create a value using default constructor. Since the value type of your map is Object, new Objects are created where null is.

In order to stop this behavior:

  • use @CreateIfNull( value = false )
  • use mapName_CreateIfNull=false in classname-convertion.properties file.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号