mirror of
https://github.com/apache/struts.git
synced 2026-08-07 15:46:57 +00:00
WW-1923 Attributes "value", "startDate", and "endDate" must be evaluated as Object instead of String
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@538771 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -23,6 +23,7 @@ package org.apache.struts2.dojo.components;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@@ -73,6 +74,10 @@ import com.opensymphony.xwork2.util.ValueStack;
|
||||
* <td>Month - Use one or two for the numerical month, three for the abbreviation, or four for the full name, or 5 for the narrow name.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>y</td>
|
||||
* <td>Year</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>h</td>
|
||||
* <td>Hour [1-12].</td>
|
||||
* </tr>
|
||||
@@ -100,13 +105,13 @@ import com.opensymphony.xwork2.util.ValueStack;
|
||||
* 'startDate' and 'endDate':
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>RFC 3339
|
||||
* <li>SimpleDateFormat built using RFC 3339 (yyyy-MM-dd'T'HH:mm:ss)
|
||||
* <li>SimpleDateFormat.getTimeInstance(DateFormat.SHORT)
|
||||
* <li>SimpleDateFormat.getDateInstance(DateFormat.SHORT)
|
||||
* <li>SimpleDateFormat.getDateInstance(DateFormat.MEDIUM)
|
||||
* <li>SimpleDateFormat.getDateInstance(DateFormat.FULL)
|
||||
* <li>SimpleDateFormat.getDateInstance(DateFormat.LONG)
|
||||
* <li>'displayFormat' attribute value
|
||||
* <li>SimpleDateFormat built using the value of the 'displayFormat' attribute(if any)
|
||||
* </ul>
|
||||
* <!-- END SNIPPET: javadoc -->
|
||||
*
|
||||
@@ -119,8 +124,10 @@ import com.opensymphony.xwork2.util.ValueStack;
|
||||
* <s:datetimepicker name="order.date" label="Order Date" />
|
||||
* Example 2:
|
||||
* <s:datetimepicker name="delivery.date" label="Delivery Date" displayFormat="yyyy-MM-dd" />
|
||||
* Example 3:
|
||||
* Example 3:
|
||||
* <s:datetimepicker name="delivery.date" label="Delivery Date" value="%{date}" />
|
||||
* Example 3:
|
||||
* <s:datetimepicker name="delivery.date" label="Delivery Date" value="%{'2007-01-01'}" />
|
||||
* <!-- END SNIPPET: expl1 -->
|
||||
* </pre>
|
||||
* <p/>
|
||||
@@ -163,14 +170,16 @@ public class DateTimePicker extends UIBean {
|
||||
public void evaluateParams() {
|
||||
super.evaluateParams();
|
||||
|
||||
if(displayFormat != null)
|
||||
addParameter("displayFormat", findString(displayFormat));
|
||||
if(displayWeeks != null)
|
||||
addParameter("displayWeeks", findString(displayWeeks));
|
||||
if(adjustWeeks != null)
|
||||
addParameter("adjustWeeks", findValue(adjustWeeks, Boolean.class));
|
||||
if(startDate != null)
|
||||
addParameter("startDate", format(findString(startDate)));
|
||||
addParameter("startDate", format(findValue(startDate)));
|
||||
if(endDate != null)
|
||||
addParameter("endDate", format(findString(endDate)));
|
||||
addParameter("endDate", format(findValue(endDate)));
|
||||
if(weekStartsOn != null)
|
||||
addParameter("weekStartsOn", findString(weekStartsOn));
|
||||
if(staticDisplay != null)
|
||||
@@ -179,14 +188,13 @@ public class DateTimePicker extends UIBean {
|
||||
addParameter("dayWidth", findValue(dayWidth, Integer.class));
|
||||
if(language != null)
|
||||
addParameter("language", findString(language));
|
||||
if(value != null)
|
||||
addParameter("value", findString(value));
|
||||
if(value != null)
|
||||
addParameter("value", format(findValue(value)));
|
||||
|
||||
if(iconPath != null)
|
||||
addParameter("iconPath", findString(iconPath));
|
||||
if(formatLength != null)
|
||||
addParameter("formatLength", findString(formatLength));
|
||||
if(displayFormat != null)
|
||||
addParameter("displayFormat", findString(displayFormat));
|
||||
if(toggleType != null)
|
||||
addParameter("toggleType", findString(toggleType));
|
||||
if(toggleDuration != null)
|
||||
@@ -203,14 +211,10 @@ public class DateTimePicker extends UIBean {
|
||||
|
||||
// format the value to RFC 3399
|
||||
if(parameters.containsKey("value")) {
|
||||
parameters.put("nameValue", format(parameters.get("value")));
|
||||
parameters.put("nameValue", parameters.get("value"));
|
||||
} else {
|
||||
if(name != null) {
|
||||
String expr = name;
|
||||
if(altSyntax()) {
|
||||
expr = "%{" + expr + "}";
|
||||
}
|
||||
addParameter("nameValue", format(findValue(expr)));
|
||||
addParameter("nameValue", format(findValue(name)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -320,7 +324,10 @@ public class DateTimePicker extends UIBean {
|
||||
|
||||
if(obj instanceof Date) {
|
||||
return RFC3339_FORMAT.format((Date) obj);
|
||||
} else {
|
||||
} else if(obj instanceof Calendar) {
|
||||
return RFC3339_FORMAT.format(((Calendar) obj).getTime());
|
||||
}
|
||||
else {
|
||||
// try to parse a date
|
||||
String dateStr = obj.toString();
|
||||
if(dateStr.equalsIgnoreCase("today"))
|
||||
@@ -337,9 +344,14 @@ public class DateTimePicker extends UIBean {
|
||||
formats.add(SimpleDateFormat.getDateInstance(DateFormat.FULL));
|
||||
formats.add(SimpleDateFormat.getDateInstance(DateFormat.LONG));
|
||||
if (this.displayFormat != null) {
|
||||
SimpleDateFormat displayFormat = new SimpleDateFormat(
|
||||
try {
|
||||
SimpleDateFormat displayFormat = new SimpleDateFormat(
|
||||
(String) getParameters().get("displayFormat"));
|
||||
formats.add(displayFormat);
|
||||
formats.add(displayFormat);
|
||||
} catch (Exception e) {
|
||||
// don't use it then (this attribute is used by Dojo, not java code)
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
for (DateFormat format : formats) {
|
||||
|
||||
+35
-18
@@ -25,9 +25,6 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.servlet.jsp.JspException;
|
||||
|
||||
import org.apache.struts2.dojo.TestAction;
|
||||
import org.apache.struts2.dojo.components.DateTimePicker;
|
||||
|
||||
/**
|
||||
@@ -45,15 +42,15 @@ public class DateTimePickerTagTest extends AbstractUITagTest {
|
||||
tag.setAdjustWeeks("true");
|
||||
tag.setDayWidth("b");
|
||||
tag.setDisplayWeeks("true");
|
||||
tag.setEndDate("01-01-2008");
|
||||
tag.setStartDate("01-01-2007");
|
||||
tag.setEndDate("%{'2008-01-01'}");
|
||||
tag.setStartDate("%{'2008-02-02'}");
|
||||
tag.setStaticDisplay("false");
|
||||
tag.setWeekStartsOn("g");
|
||||
tag.setName("h");
|
||||
tag.setLanguage("i");
|
||||
tag.setTemplateCssPath("j");
|
||||
tag.setValueNotifyTopics("k");
|
||||
tag.setValue("l");
|
||||
tag.setValue("%{'2008-03-03'}");
|
||||
tag.doStartTag();
|
||||
tag.doEndTag();
|
||||
|
||||
@@ -95,34 +92,54 @@ public class DateTimePickerTagTest extends AbstractUITagTest {
|
||||
|
||||
}
|
||||
|
||||
private void assertDateProperty(String property, DateTimePickerTag tag, Date date) throws Exception {
|
||||
DateFormat shortTimeFormat = DateFormat.getTimeInstance(DateFormat.SHORT);
|
||||
DateFormat shortFormat = DateFormat.getDateInstance(DateFormat.SHORT);
|
||||
DateFormat mediumFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);
|
||||
DateFormat longFormat = DateFormat.getDateInstance(DateFormat.LONG);
|
||||
DateFormat fullFormat = DateFormat.getDateInstance(DateFormat.FULL);
|
||||
private void assertDateProperty(String property, DateTimePickerTag tag, final Date date) throws Exception {
|
||||
final DateFormat shortTimeFormat = DateFormat.getTimeInstance(DateFormat.SHORT);
|
||||
final DateFormat shortFormat = DateFormat.getDateInstance(DateFormat.SHORT);
|
||||
final DateFormat mediumFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);
|
||||
final DateFormat longFormat = DateFormat.getDateInstance(DateFormat.LONG);
|
||||
final DateFormat fullFormat = DateFormat.getDateInstance(DateFormat.FULL);
|
||||
//try a Date value
|
||||
stack.set("date", date);
|
||||
assertDateValue(property, tag, date, true, false);
|
||||
|
||||
//try a Calendar value
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
stack.set("date", calendar);
|
||||
assertDateValue(property, tag, date, true, false);
|
||||
|
||||
//try an object whose to string returns a parseable date
|
||||
stack.set("date", new Object() {
|
||||
|
||||
// try short format on 'value'
|
||||
@Override
|
||||
public String toString() {
|
||||
return fullFormat.format(date);
|
||||
}
|
||||
|
||||
});
|
||||
assertDateValue(property, tag, date, true, false);
|
||||
|
||||
// try short format
|
||||
stack.set("date", shortFormat.format(date));
|
||||
assertDateValue(property, tag, date, true, false);
|
||||
|
||||
//try medium format on 'value'
|
||||
//try medium format
|
||||
stack.set("date", mediumFormat.format(date));
|
||||
assertDateValue(property, tag, date, true, false);
|
||||
|
||||
//try long format on 'value'
|
||||
//try long format
|
||||
stack.set("date", longFormat.format(date));
|
||||
assertDateValue(property, tag, date, true, false);
|
||||
|
||||
//try long format on 'value'
|
||||
//try full format
|
||||
stack.set("date", fullFormat.format(date));
|
||||
assertDateValue(property, tag, date, true, false);
|
||||
|
||||
//try RFC 3339 format on 'value'
|
||||
//try RFC 3339 format
|
||||
stack.set("date", RFC3339_FORMAT.format(date));
|
||||
assertDateValue(property, tag, date, true, false);
|
||||
|
||||
//try short time format on 'value'
|
||||
//try short time format
|
||||
stack.set("date", shortTimeFormat.format(date));
|
||||
assertDateValue(property, tag, date, false, true);
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,13 +1,13 @@
|
||||
<div dojoType="struts:StrutsDatePicker"
|
||||
id="id"
|
||||
value="l"
|
||||
value="2008-03-03"
|
||||
lang="i"
|
||||
name="h"
|
||||
inputName="dojo.h"
|
||||
displayWeeks="true"
|
||||
adjustWeeks="true"
|
||||
startDate="01-01-2007"
|
||||
endDate="01-01-2008"
|
||||
startDate="2008-02-02"
|
||||
endDate="2008-01-01"
|
||||
weekStartsOn="g"
|
||||
staticDisplay="false"
|
||||
templateCssPath="j"
|
||||
|
||||
Reference in New Issue
Block a user