Strange OGNL behaviour when using #this in s:select

拟墨画扇 提交于 2020-01-14 14:26:48

问题


Consider the following where availableExclusions is an array of Date objects.

<s:select listValue="(new java.text.SimpleDateFormat('MM/dd/yyyy')).format(new java.util.Date(#this[0].time))" size="25" id="inputExclusionDates" name="available" list="availableExclusions" multiple="true" cssClass="multi-select" />

I created the above in response to this question How would I format a list of dates within a struts 2 select tag? (and I also recommended that the other solution may be the better way to go). Regardless if using such long OGNL expression is a good idea or not, I can't see the need for: new java.util.Date(#this[0].time) despite creating that fragment out of frustration and to my surprise found it worked where the seemingly equivalent #this[0] did not (produced no output).

If we substitute in listValue="#this[0].class" we see what we would expect: class java.util.Date

Creating a new Date behaves as expected, and calling the deprecated properties of Date such as listValue="#this[0].day" produces the expected output.

Why must I use the redundant expression new java.util.Date(#this[0].time) instead of #this[0] in this select statement?

Using Struts 2.3.1.2


回答1:


Because #this[0] is automatically converted to String. If you turn log level to debug you can see an exception message that's normally suppressed.



来源:https://stackoverflow.com/questions/10474967/strange-ognl-behaviour-when-using-this-in-sselect

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!