| java.lang.Object org.apache.struts2.components.Component org.apache.struts2.components.Date
Date | public class Date extends Component (Code) | |
Format Date object in different ways.
The date tag will allow you to format a Date in a quick and easy way.
You can specify a custom format (eg. "dd/MM/yyyy hh:mm"), you can generate
easy readable notations (like "in 2 hours, 14 minutes"), or you can just fall back
on a predefined format with key 'struts.date.format' in your properties file.
If that key is not defined, it will finally fall back to the default DateFormat.MEDIUM
formatting.
Note: If the requested Date object isn't found on the stack, a blank will be returned.
Configurable attributes are :-
Following how the date component will work, depending on the value of nice attribute
(which by default is false) and the format attribute.
Condition 1: With nice attribute as true
i18n key |
default |
struts.date.format.past |
{0} ago |
struts.date.format.future |
in {0} |
struts.date.format.seconds |
an instant |
struts.date.format.minutes |
{0,choice,1#one minute|1<{0} minutes} |
struts.date.format.hours |
{0,choice,1#one hour|1<{0} hours}{1,choice,0#|1#, one minute|1<, {1} minutes} |
struts.date.format.days |
{0,choice,1#one day|1<{0} days}{1,choice,0#|1#, one hour|1<, {1} hours} |
struts.date.format.years |
{0,choice,1#one year|1<{0} years}{1,choice,0#|1#, one day|1<, {1} days} |
Condition 2: With nice attribute as false and format attribute is specified eg. dd/MM/yyyyy
In this case the format attribute will be used.
Condition 3: With nice attribute as false and no format attribute is specified
i18n key |
default |
struts.date.format |
if one is not found DateFormat.MEDIUM format will be used |
Examples
<s:date name="person.birthday" format="dd/MM/yyyy" />
<s:date name="person.birthday" format="%{getText('some.i18n.key')}" />
<s:date name="person.birthday" nice="true" />
<s:date name="person.birthday" />
Date
|
Constructor Summary | |
public | Date(ValueStack stack) |
DATETAG_PROPERTY | final public static String DATETAG_PROPERTY(Code) | | Property name to fall back when no format is specified
|
DATETAG_PROPERTY_DAYS | final public static String DATETAG_PROPERTY_DAYS(Code) | | Property name that defines the days notation (default: {0,choice,1#one day|1<{0} days}{1,choice,0#|1#, one hour|1<,
{1} hours})
|
DATETAG_PROPERTY_FUTURE | final public static String DATETAG_PROPERTY_FUTURE(Code) | | Property name that defines the future notation (default: in {0})
|
DATETAG_PROPERTY_HOURS | final public static String DATETAG_PROPERTY_HOURS(Code) | | Property name that defines the hours notation (default: {0,choice,1#one hour|1<{0} hours}{1,choice,0#|1#, one
minute|1<, {1} minutes})
|
DATETAG_PROPERTY_MINUTES | final public static String DATETAG_PROPERTY_MINUTES(Code) | | Property name that defines the minutes notation (default: {0,choice,1#one minute|1<{0} minutes})
|
DATETAG_PROPERTY_PAST | final public static String DATETAG_PROPERTY_PAST(Code) | | Property name that defines the past notation (default: {0} ago)
|
DATETAG_PROPERTY_SECONDS | final public static String DATETAG_PROPERTY_SECONDS(Code) | | Property name that defines the seconds notation (default: in instant)
|
DATETAG_PROPERTY_YEARS | final public static String DATETAG_PROPERTY_YEARS(Code) | | Property name that defines the years notation (default: {0,choice,1#one year|1<{0} years}{1,choice,0#|1#, one
day|1<, {1} days})
|
Date | public Date(ValueStack stack)(Code) | | |
formatTime | public String formatTime(TextProvider tp, java.util.Date date)(Code) | | Calculates the difference in time from now to the given date, and outputs it nicely. An example: Now =
2006/03/12 13:38:00, date = 2006/03/12 15:50:00 will output "in 1 hour, 12 minutes".
Parameters: tp - text provider Parameters: date - the date the date nicely |
getFormat | public String getFormat()(Code) | | Returns the format. |
isNice | public boolean isNice()(Code) | | Returns the nice. |
setNice | public void setNice(boolean nice)(Code) | | |
Methods inherited from org.apache.struts2.components.Component | public void addAllParameters(Map params)(Code)(Java Doc) public void addParameter(String key, Object value)(Code)(Java Doc) public boolean altSyntax()(Code)(Java Doc) public void copyParams(Map params)(Code)(Java Doc) protected String determineActionURL(String action, String namespace, String method, HttpServletRequest req, HttpServletResponse res, Map parameters, String scheme, boolean includeContext, boolean encodeResult)(Code)(Java Doc) protected String determineActionURL(String action, String namespace, String method, HttpServletRequest req, HttpServletResponse res, Map parameters, String scheme, boolean includeContext, boolean encodeResult, boolean forceAddSchemeHostAndPort, boolean escapeAmp)(Code)(Java Doc) protected String determineNamespace(String namespace, ValueStack stack, HttpServletRequest req)(Code)(Java Doc) public boolean end(Writer writer, String body)(Code)(Java Doc) protected boolean end(Writer writer, String body, boolean popComponentStack)(Code)(Java Doc) protected StrutsException fieldError(String field, String errorMsg, Exception e)(Code)(Java Doc) protected Component findAncestor(Class clazz)(Code)(Java Doc) protected String findString(String expr)(Code)(Java Doc) protected String findString(String expr, String field, String errorMsg)(Code)(Java Doc) protected Object findValue(String expr)(Code)(Java Doc) protected Object findValue(String expr, String field, String errorMsg)(Code)(Java Doc) protected Object findValue(String expr, Class toType)(Code)(Java Doc) public Stack getComponentStack()(Code)(Java Doc) public String getId()(Code)(Java Doc) public Map getParameters()(Code)(Java Doc) public ValueStack getStack()(Code)(Java Doc) protected void popComponentStack()(Code)(Java Doc) public void setActionMapper(ActionMapper mapper)(Code)(Java Doc) public void setId(String id)(Code)(Java Doc) public boolean start(Writer writer)(Code)(Java Doc) protected String toString(Throwable t)(Code)(Java Doc) public boolean usesBody()(Code)(Java Doc)
|
|
|