gpt4 book ai didi

java - 在 s :select 中使用 #this 时奇怪的 OGNL 行为

转载 作者:塔克拉玛干 更新时间:2023-11-02 18:58:08 26 4
gpt4 key购买 nike

考虑以下内容,其中 availableExclusions 是 Date 对象的数组。

<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" />

我创建了上面的内容来回答这个问题 How would I format a list of dates within a struts 2 select tag? (我还建议其他解决方案可能是更好的方法)。不管使用这么长的 OGNL 表达式是否是个好主意,我都看不到需要: new java.util.Date(#this[0].time) 尽管创建了那个片段令人沮丧的是,令我惊讶的是,它在看似等效的 #this[0] 没有的地方起作用(没有产生输出)。

如果我们在 listValue="#this[0].class" 中进行替换,我们会看到预期的结果:class java.util.Date

创建新 Date 的行为符合预期,调用 Date 的弃用属性(例如 listValue="#this[0].day")会产生预期的输出。

为什么我必须使用冗余表达式 new java.util.Date(#this[0].time) 而不是 #this[0] 在这个选择语句中?

使用 Struts 2.3.1.2

最佳答案

因为#this[0]会自动转成String。如果将日志级别切换为调试,您会看到一条通常被抑制的异常消息。

关于java - 在 s :select 中使用 #this 时奇怪的 OGNL 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10474967/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com