如何格式化Struts 2 select标签中的日期列表? [英] How would I format a list of dates within a struts 2 select tag?

查看:104
本文介绍了如何格式化Struts 2 select标签中的日期列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在struts 2 select标签内设置日期格式,但是这样做有困难.我知道这里有一个struts 2日期标签,但我不认为这是我想要的.

I am trying to format dates within a struts 2 select tag but I am having difficulty doing so. I know there is a struts 2 date tag but I don't think that is what I am looking for.

我在这里所做的是在一个选择框内填充一个(周末)日期列表,在这里我可以选择要添加到员工休假表中的日期.基本上,我正在尝试对它们进行格式化,以使其显示得很好且整洁(MM/dd/yyyy),但我似乎找不到正确的方法来做到这一点.我尝试在下面的列表之间插入格式标签,尝试在标签中使用format.date参数,并尝试使用listValue格式化日期,但似乎无济于事.我在这里想念东西吗?

What I am doing here is populating a select box with a list of (week end)dates where I can choose which dates to add to an employee's time off sheet. Basically I am trying to format them so that it shows up nice and neat (MM/dd/yyyy) but I can't seem to find the correct way to do this. I have tried inserting a format tag in between my list below, I have tried using a format.date parameter in the tag, and I have tried using listValue to format the dates but nothing seems to be working. Am I missing something here?

<s:select size="25" id="inputExclusionDates" name="available" list="availableExclusions" multiple="true" cssClass="multi-select" />

推荐答案

出于乐趣,我花时间弄清楚了如何在OGNL中执行此操作,由于出现了一些奇怪的皱纹,这并不像我预期的那么容易.

For fun I took the time to figure out how to do this in OGNL which was not as easy as I expected because of some strange wrinkle.

以下内容与提供java.text.SimpleDateFormat属性的操作一起使用,该属性称为simpleDateFormat(请注意,在这些select标记中唯一不同的部分是listValue属性):

The following works with an action which supplies a java.text.SimpleDateFormat property called simpleDateFormat (Note the only part that is different in these select tags is the listValue property):

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

以下内容与上述相同,但是在JSP中执行了所有操作:

The following does the same as the above but does everything in the JSP:

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

现在我提到了皱纹,那些有好眼睛的人会注意到表面上似乎多余的表情new java.util.Date(#this[0].time),毕竟我应该只能说#this[0].毕竟这是有道理的,但不起作用.因此,由于这让我有些困惑,所以我会问一个问题: Strange在s中使用#this时的OGNL行为:选择

Now I mentioned a wrinkle, those with good eyes will have noted the seemingly redundant expression new java.util.Date(#this[0].time) after all I should just be able to say #this[0]. That would make sense after all but it does not work. So since this confused me somewhat I'll ask a question about it: Strange OGNL behaviour when using #this in s:select

这篇关于如何格式化Struts 2 select标签中的日期列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆