문제

I iterate a list of rows from a database table which contains a column of type DateTime in MySQL as follows (incomplete version of code).

<s:iterator value="discounts" status="loopStatus">

    <joda:format var="formattedStartDate" 
                 value="${discountStartDate}" 
                 pattern="dd-MMM-yyyy HH:mm:ss" style="F-" 
                 dateTimeZone="Asia/Kolkata"/>

    <td><c:out value="${formattedStartDate}"/></td>
</s:iterator>

Can we format date-time using <joda:format> along with struts tags?

Can I replace,

<c:out value="${formattedStartDate}"/>

with something like,

<s:property value="%{formattedStartDate}" />

It does not work. The column remains empty after the complete list is iterated because the actual property is discountStartDate in the corresponding model that the <s:property> tag is missing.


Additional information:

Formatting of dates is done internally by using a custom converter but I want to display dates in this dd-MMM-yyyy HH:mm:ss format (which is done by the converter) which is not accepted by the jQuery date-time picker that I'm using.

Therefore the dates listed in the HTML table in the specified format can not be edited unless they are given the format that is accepted by the date-time picker (MM/dd/yyyy HH:mm:ss) at the time of editing of rows.

Please don't just say, use another date-time picker that can accept the format dd-MMM-yyyy HH:mm:ss. This need can arise at a different place too.


Actually I need the value of formattedStartDate in <s:param> inside <s:url> but I have not mentioned that for the sake of simplicity. Anyway, the value of formattedStartDate should be given/assigned to Struts tags (if possible).

도움이 되었습니까?

해결책

If you don't use scope attribute of <joda:format> tag the default scope will be page scope. In order to get it in Struts2 tags use #attr that will search page, request, session, and then application scopes.

<s:iterator value="discounts" status="loopStatus">
    <joda:format var="formattedStartDate" 
                 value="${discountStartDate}" 
                 pattern="dd-MMM-yyyy HH:mm:ss" style="F-" 
                 dateTimeZone="Asia/Kolkata"/>

    <td><s:property value="#attr.formattedStartDate" /></td>
</s:iterator>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top