struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From musa...@apache.org
Subject svn commit: r538771 - in /struts/struts2/trunk/plugins/dojo/src: main/java/org/apache/struts2/dojo/components/ test/java/org/apache/struts2/dojo/views/jsp/ui/ test/resources/org/apache/struts2/dojo/views/jsp/ui/
Date Wed, 16 May 2007 22:59:20 GMT
Author: musachy
Date: Wed May 16 15:59:20 2007
New Revision: 538771

URL: http://svn.apache.org/viewvc?view=rev&rev=538771
Log:
WW-1923 Attributes "value", "startDate", and "endDate" must be evaluated as Object instead
of String

Modified:
    struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/DateTimePicker.java
    struts/struts2/trunk/plugins/dojo/src/test/java/org/apache/struts2/dojo/views/jsp/ui/DateTimePickerTagTest.java
    struts/struts2/trunk/plugins/dojo/src/test/resources/org/apache/struts2/dojo/views/jsp/ui/DateTimePickerTagTest-1.txt

Modified: struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/DateTimePicker.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/DateTimePicker.java?view=diff&rev=538771&r1=538770&r2=538771
==============================================================================
--- struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/DateTimePicker.java
(original)
+++ struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/DateTimePicker.java
Wed May 16 15:59:20 2007
@@ -23,6 +23,7 @@
 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 @@
  *      <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 @@
  * '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 @@
  *     &lt;s:datetimepicker name="order.date" label="Order Date" /&gt;
  * Example 2:
  *     &lt;s:datetimepicker name="delivery.date" label="Delivery Date" displayFormat="yyyy-MM-dd"
 /&gt;
- * Example 3:    
+ * Example 3:   
  *      &lt;s:datetimepicker name="delivery.date" label="Delivery Date" value="%{date}"
 /&gt;
+ *  Example 3:    
+ *      &lt;s:datetimepicker name="delivery.date" label="Delivery Date" value="%{'2007-01-01'}"
 /&gt;     
  * <!-- END SNIPPET: expl1 -->
  * </pre>
  * <p/>
@@ -163,14 +170,16 @@
     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 @@
             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 @@
         
         // 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 @@
 
         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 @@
             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) {

Modified: struts/struts2/trunk/plugins/dojo/src/test/java/org/apache/struts2/dojo/views/jsp/ui/DateTimePickerTagTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/test/java/org/apache/struts2/dojo/views/jsp/ui/DateTimePickerTagTest.java?view=diff&rev=538771&r1=538770&r2=538771
==============================================================================
--- struts/struts2/trunk/plugins/dojo/src/test/java/org/apache/struts2/dojo/views/jsp/ui/DateTimePickerTagTest.java
(original)
+++ struts/struts2/trunk/plugins/dojo/src/test/java/org/apache/struts2/dojo/views/jsp/ui/DateTimePickerTagTest.java
Wed May 16 15:59:20 2007
@@ -25,9 +25,6 @@
 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 @@
         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 @@
 
     }
 
-    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);
     }

Modified: struts/struts2/trunk/plugins/dojo/src/test/resources/org/apache/struts2/dojo/views/jsp/ui/DateTimePickerTagTest-1.txt
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/test/resources/org/apache/struts2/dojo/views/jsp/ui/DateTimePickerTagTest-1.txt?view=diff&rev=538771&r1=538770&r2=538771
==============================================================================
--- struts/struts2/trunk/plugins/dojo/src/test/resources/org/apache/struts2/dojo/views/jsp/ui/DateTimePickerTagTest-1.txt
(original)
+++ struts/struts2/trunk/plugins/dojo/src/test/resources/org/apache/struts2/dojo/views/jsp/ui/DateTimePickerTagTest-1.txt
Wed May 16 15:59:20 2007
@@ -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"



Mime
View raw message