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.
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" />
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.
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):
The following does the same as the above but does everything in the JSP:
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