I have a JSP page where i am getting a Date value from my action class. I am not able to understand how it is handled as:
<s:property value="#someDate"/>
gives me date
2/7/14
whereas
<s:property value="{#someDate}"/>
gives me Date as
[Wed Feb 7 00:00:00 IST 2014]
Can someone tell me how date value is actually handled here, as date is returned in different formats?
The date tag allows to format a Date in a quick and easy way. User can specify a custom format (eg. "dd/MM/yyyy hh:mm"), can generate easy readable notations (like "in 2 hours, 14 minutes"), or can just fall back on a predefined format with key 'struts. date.
You can create Struts HTML tags from the Struts HTML Tags drawer. These tags are used to create Struts input forms, as well as other tags generally useful in the creation of HTML-based user interfaces. The output is HTML 4.01 compliant or XHTML 1.0 when in XHTML mode.
Nice Question.
<s:property value="{#someDate}"/>
is equal to <s:property value="someDate.toString()"/
> or ${someDate}
where as <s:property value="someDate"/>
is using built in type conversion of xwork2 which uses the SHORT format for the Locale associated with the current request for dates.
See Built in Type Conversion Support
value="{#someDate}" means value="someDate.toString()"
it converts date to date.tosting() that is why you are getting [Wed Feb 7 00:00:00 IST 2014]
To handle date formats there is a special tag in struts2
<s:date name="someDate" format="dd/MM/yyyy" />
Prints
17/04/2014
Also see
<s:date name="someDate" format="dd/MMM/yyyy" />
Prints
17/Apr/2014
Also there is attibute nice="true"
<s:date name="someDate" nice="true" />
Prints
2 days ago
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With