OGNL weird behavior when using #this in s: select

Consider where available. Exceptions are 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 do I format the date list in the select 2 tag? ... (and I also recommended that another solution might be the best way to go). Despite the fact that using such a long OGNL expression is a good idea or not, I don’t see the need: new java.util.Date(#this[0].time)despite creating this fragment due to disappointment and, to my surprise, I found that it worked where it would seem that equivalent #this[0]did not exit).

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

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

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

Using Struts 2.3.1.2

+3
source share
1 answer

Because it is #this[0]automatically converted to String. If you set the log level for debugging, you can see the exception message, which is usually suppressed.

+3
source

All Articles