WW-1729 Add "templateCssPath" attribute DateTimePicker

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/branches/STRUTS_2_0_X@508602 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Musachy Barroso
2007-02-16 21:53:54 +00:00
parent 2cab82fafc
commit d7189a6648
7 changed files with 33 additions and 7 deletions
@@ -127,7 +127,7 @@ import com.opensymphony.xwork2.util.ValueStack;
public class DateTimePicker extends UIBean {
final public static String TEMPLATE = "datetimepicker";
final private static SimpleDateFormat RFC3399_FORMAT = new SimpleDateFormat(
final private static SimpleDateFormat RFC3339_FORMAT = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss");
final protected static Log LOG = LogFactory.getLog(DateTimePicker.class);
@@ -146,6 +146,7 @@ public class DateTimePicker extends UIBean {
protected String staticDisplay;
protected String dayWidth;
protected String language;
protected String templateCssPath;
public DateTimePicker(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
super(stack, request, response);
@@ -191,7 +192,9 @@ public class DateTimePicker extends UIBean {
addParameter("type", findString(type));
else
addParameter("type", "date");
if(templateCssPath != null)
addParameter("templateCssPath", findString(templateCssPath));
// format the value to RFC 3399
if(parameters.containsKey("value")) {
parameters.put("nameValue", format(parameters.get("value")));
@@ -279,17 +282,22 @@ public class DateTimePicker extends UIBean {
this.toggleType = toggleType;
}
@StrutsTagAttribute(description="Template css path")
public void setTemplateCssPath(String templateCssPath) {
this.templateCssPath = templateCssPath;
}
private String format(Object obj) {
if(obj == null)
return null;
if(obj instanceof Date) {
return RFC3399_FORMAT.format((Date) obj);
return RFC3339_FORMAT.format((Date) obj);
} else {
// try to parse a date
String dateStr = obj.toString();
if(dateStr.equalsIgnoreCase("today"))
return RFC3399_FORMAT.format(new Date());
return RFC3339_FORMAT.format(new Date());
try {
Date date = null;
@@ -297,7 +305,7 @@ public class DateTimePicker extends UIBean {
SimpleDateFormat format = new SimpleDateFormat(
this.displayFormat);
date = format.parse(dateStr);
return RFC3399_FORMAT.format(date);
return RFC3339_FORMAT.format(date);
} else {
// last resource to assume already in correct/default format
return dateStr;
@@ -50,6 +50,7 @@ public class DateTimePickerTag extends AbstractUITag {
protected String toggleType;
protected String toggleDuration;
protected String type;
protected String templateCssPath;
public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
return new DateTimePicker(stack, req, res);
@@ -73,6 +74,7 @@ public class DateTimePickerTag extends AbstractUITag {
dateTimePicker.setToggleType(toggleType);
dateTimePicker.setToggleDuration(toggleDuration);
dateTimePicker.setType(type);
dateTimePicker.setTemplateCssPath(templateCssPath);
}
public void setAdjustWeeks(String adjustWeeks) {
@@ -130,4 +132,8 @@ public class DateTimePickerTag extends AbstractUITag {
public void setType(String type) {
this.type = type;
}
public void setTemplateCssPath(String templateCssPath) {
this.templateCssPath = templateCssPath;
}
}
@@ -1 +0,0 @@
<#include "/${parameters.templateDir}/simple/dropdowndatetimepicker.ftl" />
@@ -51,7 +51,7 @@
style="${parameters.cssStyle?html}"<#rt/>
</#if>
<#if parameters.iconPath?if_exists != "">
iconURL="${parameters.iconPath}"<#rt/>
iconURL="<@s.url value='${parameters.iconPath}' encode="false" includeParams='none'/>"<#rt/>
</#if>
<#if parameters.formatLength?if_exists != "">
formatLength="${parameters.formatLength?html}"<#rt/>
@@ -65,6 +65,9 @@
<#if parameters.toggleDuration?exists>
containerToggleDuration="${parameters.toggleDuration?string?html}"<#rt/>
</#if>
<#if parameters.templateCssPath?exists>
templateCssPath="<@s.url value='${parameters.templateCssPath}' encode="false" includeParams='none'/>"
</#if>
saveFormat="rfc"<#rt/>
<#include "/${parameters.templateDir}/simple/scripting-events.ftl" />
></div>
@@ -323,6 +323,14 @@ Please do not edit it directly.
<td align="left" valign="top">String</td>
<td align="left" valign="top">The template (other than default) to use for rendering the element</td>
</tr>
<tr>
<td align="left" valign="top">templateCssPath</td>
<td align="left" valign="top">false</td>
<td align="left" valign="top"></td>
<td align="left" valign="top">true</td>
<td align="left" valign="top">String</td>
<td align="left" valign="top">Template css path</td>
</tr>
<tr>
<td align="left" valign="top">templateDir</td>
<td align="left" valign="top">false</td>
@@ -59,6 +59,7 @@ public class DateTimePickerTagTest extends AbstractUITagTest {
tag.setWeekStartsOn("g");
tag.setName("h");
tag.setLanguage("i");
tag.setTemplateCssPath("j");
tag.doStartTag();
tag.doEndTag();
@@ -16,6 +16,7 @@
endDate="d"
weekStartsOn="g"
staticDisplay="false"
templateCssPath="j"
saveFormat="rfc">
</div>
</td>