You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by mu...@apache.org on 2007/08/26 21:18:17 UTC

svn commit: r569863 [2/4] - in /struts/struts2/trunk/plugins/dojo/src: main/java/org/apache/struts2/dojo/components/ main/java/org/apache/struts2/dojo/views/jsp/ui/ main/resources/template/ajax/ profile/ test/java/org/apache/struts2/dojo/views/jsp/ui/ ...

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?rev=569863&r1=569862&r2=569863&view=diff
==============================================================================
--- 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 Sun Aug 26 12:18:15 2007
@@ -1,420 +1,429 @@
-/*
- * $Id: DateTimePicker.java 512580 2007-02-28 02:48:06Z musachy $
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-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;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.struts2.components.UIBean;
-import org.apache.struts2.views.annotations.StrutsTag;
-import org.apache.struts2.views.annotations.StrutsTagAttribute;
-import org.apache.struts2.views.annotations.StrutsTagSkipInheritance;
-
-import com.opensymphony.xwork2.util.ValueStack;
-
-/**
- * <!-- START SNIPPET: javadoc -->
- * <p>
- * Renders a date/time picker in a dropdown container.
- * </p>
- * <p>
- * A stand-alone DateTimePicker widget that makes it easy to select a date/time, or increment by week, month,
- * and/or year.
- * </p>
- *
- * <p>
- * It is possible to customize the user-visible formatting with either the
- * 'formatLength' (long, short, medium or full) or 'displayFormat' attributes. By defaulty current
- * locale will be used.</p>
- * </p>
- * 
- * Syntax supported by 'displayFormat' is (http://www.unicode.org/reports/tr35/tr35-4.html#Date_Format_Patterns):-
- * <table border="1">
- *   <tr>
- *      <td>Format</td>
- *      <td>Description</td>
- *   </tr>
- *   <tr>
- *      <td>d</td>
- *      <td>Day of the month</td>
- *   </tr>
- *   <tr>
- *      <td>D</td>
- *      <td>Day of year</td>
- *   </tr>
- *   <tr>
- *      <td>M</td>
- *      <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>
- *   <tr>
- *      <td>H</td>
- *      <td>Hour [0-23].</td>
- *   </tr>
- *   <tr>
- *      <td>m</td>
- *      <td>Minute. Use one or two for zero padding.</td>
- *   </tr>
- *   <tr>
- *      <td>s</td>
- *      <td>Second. Use one or two for zero padding.</td>
- *   </tr>
- * </table>
- * 
- * <p>
- * The value sent to the server is a locale-independent value, in a hidden field as defined 
- * by the name attribute. The value will be formatted conforming to RFC3 339 
- * (yyyy-MM-dd'T'HH:mm:ss)
- * </p>
- * <p>
- * The following formats(in order) will be used to parse the values of the attributes 'value', 
- * 'startDate' and 'endDate':
- * </p>
- * <ul>
- *   <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>SimpleDateFormat built using the value of the 'displayFormat' attribute(if any)
- * </ul>
- * <!-- END SNIPPET: javadoc -->
- *
- * <b>Examples</b>
- *
- * <pre>
- * <!-- START SNIPPET: example1 -->
- *
- * Example 1:
- *     &lt;sx:datetimepicker name="order.date" label="Order Date" /&gt;
- * Example 2:
- *     &lt;sx:datetimepicker name="delivery.date" label="Delivery Date" displayFormat="yyyy-MM-dd"  /&gt;
- * Example 3:   
- *      &lt;sx:datetimepicker name="delivery.date" label="Delivery Date" value="%{date}"  /&gt;
- * Example 4:    
- *      &lt;sx:datetimepicker name="delivery.date" label="Delivery Date" value="%{'2007-01-01'}"  /&gt;
- * Example 5:           
- *      &lt;sx:datetimepicker name="order.date" label="Order Date" value="%{'today'}"/&gt;
- * <!-- END SNIPPET: example1 -->
- * </pre>
- * 
- * <!-- START SNIPPET: example2 -->
- * <p>Getting and getting the datetimepicker value, from JavaScript</p>
- * <pre>
- * &lt;sx:datetimepicker id="picker" label="Order Date" /&gt;
- * &lt;script type="text/javascript"&gt;
- *   function setValue() {
- *      var picker = dojo.widget.byId("picker");
- *      
- *      //string value
- *      picker.setValue('2007-01-01');
- *      
- *      //Date value
- *      picker.setValue(new Date());
- *   }
- *   
- *   function showValue() {
- *      var picker = dojo.widget.byId("picker");
- *      
- *      //string value
- *      var stringValue = picker.getValue();
- *      alert(stringValue);
- *      
- *      //date value
- *      var dateValue = picker.getDate();
- *      alert(dateValue);
- *   }
- * &lt;/script&gt;
- * </pre>
- * <!-- END SNIPPET: example2 -->
- * 
- * <!-- START SNIPPET: example3 -->
- * <p>Publish topic when value changes</p>
- * <pre>
- * &lt;sx:datetimepicker id="picker" label="Order Date" valueNotifyTopics="/value"/&gt;
- * 
- * &lt;script type="text/javascript"&gt;
- * dojo.event.topic.subscribe("/value", function(textEntered, date, widget){
- *     alert('value changed');
- *     //textEntered: String enetered in the textbox
- *     //date: JavaScript Date object with the value selected
- *     //widet: widget that published the topic 
- * });
- * &lt;/script&gt;  
- * </pre>
- * <!-- END SNIPPET: example3 -->
- */
-@StrutsTag(name="datetimepicker", tldTagClass="org.apache.struts2.dojo.views.jsp.ui.DateTimePickerTag", description="Render datetimepicker")
-public class DateTimePicker extends UIBean {
-
-    final public static String TEMPLATE = "datetimepicker";
-    final private static SimpleDateFormat RFC3339_FORMAT = new SimpleDateFormat(
-    "yyyy-MM-dd'T'HH:mm:ss");
-    final protected static Log LOG = LogFactory.getLog(DateTimePicker.class);
-    
-    protected String iconPath;
-    protected String formatLength;
-    protected String displayFormat;
-    protected String toggleType;
-    protected String toggleDuration;
-    protected String type;
-
-    protected String displayWeeks;
-    protected String adjustWeeks;
-    protected String startDate;
-    protected String endDate;
-    protected String weekStartsOn;
-    protected String staticDisplay;
-    protected String dayWidth;
-    protected String language;
-    protected String templateCssPath;
-    protected String valueNotifyTopics;
-
-    public DateTimePicker(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
-        super(stack, request, response);
-    }
-
-    protected String getDefaultTemplate() {
-        return TEMPLATE;
-    }
-
-    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(findValue(startDate)));
-        if(endDate != null)
-            addParameter("endDate", format(findValue(endDate)));
-        if(weekStartsOn != null)
-            addParameter("weekStartsOn", findString(weekStartsOn));
-        if(staticDisplay != null)
-            addParameter("staticDisplay", findValue(staticDisplay, Boolean.class));
-        if(dayWidth != null)
-            addParameter("dayWidth", findValue(dayWidth, Integer.class));
-        if(language != null)
-            addParameter("language", findString(language));
-        if(value != null) 
-            addParameter("value", format(findValue(value)));
-   
-        if(iconPath != null)
-            addParameter("iconPath", findString(iconPath));
-        if(formatLength != null)
-            addParameter("formatLength", findString(formatLength));
-        if(toggleType != null)
-            addParameter("toggleType", findString(toggleType));
-        if(toggleDuration != null)
-            addParameter("toggleDuration", findValue(toggleDuration,
-                    Integer.class));
-        if(type != null)
-            addParameter("type", findString(type));
-        else
-            addParameter("type", "date");
-        if(templateCssPath != null)
-            addParameter("templateCssPath", findString(templateCssPath));
-        if(valueNotifyTopics != null)
-            addParameter("valueNotifyTopics", findString(valueNotifyTopics));
-        
-        // format the value to RFC 3399
-        if(parameters.containsKey("value")) {
-            parameters.put("nameValue", parameters.get("value"));
-        } else {
-            if(name != null) {
-                addParameter("nameValue", format(findValue(name)));
-            }
-        }
-    }
-    
-    @Override
-    @StrutsTagSkipInheritance
-    public void setTheme(String theme) {
-        super.setTheme(theme);
-    }
-
-    @Override
-    public String getTheme() {
-        return "ajax";
-    }
-    
-    @StrutsTagAttribute(description="If true, weekly size of calendar changes to acomodate the month if false," +
-                " 42 day format is used", type="Boolean", defaultValue="false")
-    public void setAdjustWeeks(String adjustWeeks) {
-        this.adjustWeeks = adjustWeeks;
-    }
-
-    @StrutsTagAttribute(description="How to render the names of the days in the header(narrow, abbr or wide)", defaultValue="narrow")
-    public void setDayWidth(String dayWidth) {
-        this.dayWidth = dayWidth;
-    }
-
-    @StrutsTagAttribute(description="Total weeks to display", type="Integer", defaultValue="6")
-    public void setDisplayWeeks(String displayWeeks) {
-        this.displayWeeks = displayWeeks;
-    }
-
-    @StrutsTagAttribute(description="Last available date in the calendar set", type="Date", defaultValue="2941-10-12")
-    public void setEndDate(String endDate) {
-        this.endDate = endDate;
-    }
-
-    @StrutsTagAttribute(description="First available date in the calendar set", type="Date", defaultValue="1492-10-12")
-    public void setStartDate(String startDate) {
-        this.startDate = startDate;
-    }
-
-    @StrutsTagAttribute(description="Disable all incremental controls, must pick a date in the current display", type="Boolean", defaultValue="false")
-    public void setStaticDisplay(String staticDisplay) {
-        this.staticDisplay = staticDisplay;
-    }
-
-    @StrutsTagAttribute(description="Adjusts the first day of the week 0==Sunday..6==Saturday", type="Integer", defaultValue="0")
-    public void setWeekStartsOn(String weekStartsOn) {
-        this.weekStartsOn = weekStartsOn;
-    }
-
-    @StrutsTagAttribute(description="Language to display this widget in", defaultValue="brower's specified preferred language")
-    public void setLanguage(String language) {
-        this.language = language;
-    }
-    
-    @StrutsTagAttribute(description="A pattern used for the visual display of the formatted date, e.g. dd/MM/yyyy")
-    public void setDisplayFormat(String displayFormat) {
-        this.displayFormat = displayFormat;
-    }
-
-    @StrutsTagAttribute(description="Type of formatting used for visual display. Possible values are " +
-                "long, short, medium or full", defaultValue="short")
-    public void setFormatLength(String formatLength) {
-        this.formatLength = formatLength;
-    }
-
-    @StrutsTagAttribute(description="Path to icon used for the dropdown")
-    public void setIconPath(String iconPath) {
-        this.iconPath = iconPath;
-    }
-
-    @StrutsTagAttribute(description="Duration of toggle in milliseconds", type="Integer", defaultValue="100")
-    public void setToggleDuration(String toggleDuration) {
-        this.toggleDuration = toggleDuration;
-    }
-
-    @StrutsTagAttribute(description="Defines the type of the picker on the dropdown. Possible values are 'date'" +
-                " for a DateTimePicker, and 'time' for a timePicker", defaultValue="date")
-    public void setType(String type) {
-        this.type = type;
-    }
-
-    @StrutsTagAttribute(description="oggle type of the dropdown. Possible values are plain,wipe,explode,fade", defaultValue="plain")
-    public void setToggleType(String toggleType) {
-        this.toggleType = toggleType;
-    }
-    
-    @StrutsTagAttribute(description="Template css path")
-    public void setTemplateCssPath(String templateCssPath) {
-        this.templateCssPath = templateCssPath;
-    }
-    
-    @StrutsTagAttribute(description="Preset the value of input element")
-    public void setValue(String arg0) {
-        super.setValue(arg0);
-    }
-    
-    @StrutsTagAttribute(description="Comma delimmited list of topics that will published when a value is selected")
-    public void setValueNotifyTopics(String valueNotifyTopics) {
-        this.valueNotifyTopics = valueNotifyTopics;
-    }
-    
-    private String format(Object obj) {
-        if(obj == null)
-            return null;
-
-        if(obj instanceof Date) {
-            return RFC3339_FORMAT.format((Date) obj);
-        } 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"))
-                return RFC3339_FORMAT.format(new Date());
-
-            
-            Date date = null;
-            //formats used to parse the date
-            List<DateFormat> formats = new ArrayList<DateFormat>();
-            formats.add(RFC3339_FORMAT);
-            formats.add(SimpleDateFormat.getTimeInstance(DateFormat.SHORT));
-            formats.add(SimpleDateFormat.getDateInstance(DateFormat.SHORT));
-            formats.add(SimpleDateFormat.getDateInstance(DateFormat.MEDIUM));
-            formats.add(SimpleDateFormat.getDateInstance(DateFormat.FULL));
-            formats.add(SimpleDateFormat.getDateInstance(DateFormat.LONG));
-            if (this.displayFormat != null) {
-                try {
-                    SimpleDateFormat displayFormat = new SimpleDateFormat(
-                        (String) getParameters().get("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) {
-                try {
-                    date = format.parse(dateStr);
-                    if (date != null)
-                        return RFC3339_FORMAT.format(date);
-                } catch (Exception e) {
-                    //keep going
-                }
-            }
-            
-           // last resource, assume already in correct/default format
-           if (LOG.isDebugEnabled())
-               LOG.debug("Unable to parse date " + dateStr);
-           return dateStr;
-        }
-    }
-
-}
+/*
+ * $Id: DateTimePicker.java 512580 2007-02-28 02:48:06Z musachy $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+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;
+import java.util.Random;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.struts2.components.UIBean;
+import org.apache.struts2.views.annotations.StrutsTag;
+import org.apache.struts2.views.annotations.StrutsTagAttribute;
+import org.apache.struts2.views.annotations.StrutsTagSkipInheritance;
+
+import com.opensymphony.xwork2.util.ValueStack;
+
+/**
+ * <!-- START SNIPPET: javadoc -->
+ * <p>
+ * Renders a date/time picker in a dropdown container.
+ * </p>
+ * <p>
+ * A stand-alone DateTimePicker widget that makes it easy to select a date/time, or increment by week, month,
+ * and/or year.
+ * </p>
+ *
+ * <p>
+ * It is possible to customize the user-visible formatting with either the
+ * 'formatLength' (long, short, medium or full) or 'displayFormat' attributes. By defaulty current
+ * locale will be used.</p>
+ * </p>
+ * 
+ * Syntax supported by 'displayFormat' is (http://www.unicode.org/reports/tr35/tr35-4.html#Date_Format_Patterns):-
+ * <table border="1">
+ *   <tr>
+ *      <td>Format</td>
+ *      <td>Description</td>
+ *   </tr>
+ *   <tr>
+ *      <td>d</td>
+ *      <td>Day of the month</td>
+ *   </tr>
+ *   <tr>
+ *      <td>D</td>
+ *      <td>Day of year</td>
+ *   </tr>
+ *   <tr>
+ *      <td>M</td>
+ *      <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>
+ *   <tr>
+ *      <td>H</td>
+ *      <td>Hour [0-23].</td>
+ *   </tr>
+ *   <tr>
+ *      <td>m</td>
+ *      <td>Minute. Use one or two for zero padding.</td>
+ *   </tr>
+ *   <tr>
+ *      <td>s</td>
+ *      <td>Second. Use one or two for zero padding.</td>
+ *   </tr>
+ * </table>
+ * 
+ * <p>
+ * The value sent to the server is a locale-independent value, in a hidden field as defined 
+ * by the name attribute. The value will be formatted conforming to RFC3 339 
+ * (yyyy-MM-dd'T'HH:mm:ss)
+ * </p>
+ * <p>
+ * The following formats(in order) will be used to parse the values of the attributes 'value', 
+ * 'startDate' and 'endDate':
+ * </p>
+ * <ul>
+ *   <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>SimpleDateFormat built using the value of the 'displayFormat' attribute(if any)
+ * </ul>
+ * <!-- END SNIPPET: javadoc -->
+ *
+ * <b>Examples</b>
+ *
+ * <pre>
+ * <!-- START SNIPPET: example1 -->
+ *
+ * Example 1:
+ *     &lt;sx:datetimepicker name="order.date" label="Order Date" /&gt;
+ * Example 2:
+ *     &lt;sx:datetimepicker name="delivery.date" label="Delivery Date" displayFormat="yyyy-MM-dd"  /&gt;
+ * Example 3:   
+ *      &lt;sx:datetimepicker name="delivery.date" label="Delivery Date" value="%{date}"  /&gt;
+ * Example 4:    
+ *      &lt;sx:datetimepicker name="delivery.date" label="Delivery Date" value="%{'2007-01-01'}"  /&gt;
+ * Example 5:           
+ *      &lt;sx:datetimepicker name="order.date" label="Order Date" value="%{'today'}"/&gt;
+ * <!-- END SNIPPET: example1 -->
+ * </pre>
+ * 
+ * <!-- START SNIPPET: example2 -->
+ * <p>Getting and getting the datetimepicker value, from JavaScript</p>
+ * <pre>
+ * &lt;sx:datetimepicker id="picker" label="Order Date" /&gt;
+ * &lt;script type="text/javascript"&gt;
+ *   function setValue() {
+ *      var picker = dojo.widget.byId("picker");
+ *      
+ *      //string value
+ *      picker.setValue('2007-01-01');
+ *      
+ *      //Date value
+ *      picker.setValue(new Date());
+ *   }
+ *   
+ *   function showValue() {
+ *      var picker = dojo.widget.byId("picker");
+ *      
+ *      //string value
+ *      var stringValue = picker.getValue();
+ *      alert(stringValue);
+ *      
+ *      //date value
+ *      var dateValue = picker.getDate();
+ *      alert(dateValue);
+ *   }
+ * &lt;/script&gt;
+ * </pre>
+ * <!-- END SNIPPET: example2 -->
+ * 
+ * <!-- START SNIPPET: example3 -->
+ * <p>Publish topic when value changes</p>
+ * <pre>
+ * &lt;sx:datetimepicker id="picker" label="Order Date" valueNotifyTopics="/value"/&gt;
+ * 
+ * &lt;script type="text/javascript"&gt;
+ * dojo.event.topic.subscribe("/value", function(textEntered, date, widget){
+ *     alert('value changed');
+ *     //textEntered: String enetered in the textbox
+ *     //date: JavaScript Date object with the value selected
+ *     //widet: widget that published the topic 
+ * });
+ * &lt;/script&gt;  
+ * </pre>
+ * <!-- END SNIPPET: example3 -->
+ */
+@StrutsTag(name="datetimepicker", tldTagClass="org.apache.struts2.dojo.views.jsp.ui.DateTimePickerTag", description="Render datetimepicker")
+public class DateTimePicker extends UIBean {
+
+    final public static String TEMPLATE = "datetimepicker";
+    final private static SimpleDateFormat RFC3339_FORMAT = new SimpleDateFormat(
+    "yyyy-MM-dd'T'HH:mm:ss");
+    final protected static Log LOG = LogFactory.getLog(DateTimePicker.class);
+    
+    protected String iconPath;
+    protected String formatLength;
+    protected String displayFormat;
+    protected String toggleType;
+    protected String toggleDuration;
+    protected String type;
+
+    protected String displayWeeks;
+    protected String adjustWeeks;
+    protected String startDate;
+    protected String endDate;
+    protected String weekStartsOn;
+    protected String staticDisplay;
+    protected String dayWidth;
+    protected String language;
+    protected String templateCssPath;
+    protected String valueNotifyTopics;
+
+    public DateTimePicker(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
+        super(stack, request, response);
+    }
+
+    protected String getDefaultTemplate() {
+        return TEMPLATE;
+    }
+
+    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(findValue(startDate)));
+        if(endDate != null)
+            addParameter("endDate", format(findValue(endDate)));
+        if(weekStartsOn != null)
+            addParameter("weekStartsOn", findString(weekStartsOn));
+        if(staticDisplay != null)
+            addParameter("staticDisplay", findValue(staticDisplay, Boolean.class));
+        if(dayWidth != null)
+            addParameter("dayWidth", findValue(dayWidth, Integer.class));
+        if(language != null)
+            addParameter("language", findString(language));
+        if(value != null) 
+            addParameter("value", format(findValue(value)));
+   
+        if(iconPath != null)
+            addParameter("iconPath", findString(iconPath));
+        if(formatLength != null)
+            addParameter("formatLength", findString(formatLength));
+        if(toggleType != null)
+            addParameter("toggleType", findString(toggleType));
+        if(toggleDuration != null)
+            addParameter("toggleDuration", findValue(toggleDuration,
+                    Integer.class));
+        if(type != null)
+            addParameter("type", findString(type));
+        else
+            addParameter("type", "date");
+        if(templateCssPath != null)
+            addParameter("templateCssPath", findString(templateCssPath));
+        if(valueNotifyTopics != null)
+            addParameter("valueNotifyTopics", findString(valueNotifyTopics));
+        
+        // format the value to RFC 3399
+        if(parameters.containsKey("value")) {
+            parameters.put("nameValue", parameters.get("value"));
+        } else {
+            if(name != null) {
+                addParameter("nameValue", format(findValue(name)));
+            }
+        }
+        
+        boolean generateId = !(Boolean)stack.getContext().get(Head.PARSE_CONTENT);
+        addParameter("pushId", generateId);
+        if ((this.id == null || this.id.length() == 0) && generateId) {
+            Random random = new Random();
+            this.id = "widget_" + Math.abs(random.nextInt());
+            addParameter("id", this.id);
+        }
+    }
+    
+    @Override
+    @StrutsTagSkipInheritance
+    public void setTheme(String theme) {
+        super.setTheme(theme);
+    }
+
+    @Override
+    public String getTheme() {
+        return "ajax";
+    }
+    
+    @StrutsTagAttribute(description="If true, weekly size of calendar changes to acomodate the month if false," +
+                " 42 day format is used", type="Boolean", defaultValue="false")
+    public void setAdjustWeeks(String adjustWeeks) {
+        this.adjustWeeks = adjustWeeks;
+    }
+
+    @StrutsTagAttribute(description="How to render the names of the days in the header(narrow, abbr or wide)", defaultValue="narrow")
+    public void setDayWidth(String dayWidth) {
+        this.dayWidth = dayWidth;
+    }
+
+    @StrutsTagAttribute(description="Total weeks to display", type="Integer", defaultValue="6")
+    public void setDisplayWeeks(String displayWeeks) {
+        this.displayWeeks = displayWeeks;
+    }
+
+    @StrutsTagAttribute(description="Last available date in the calendar set", type="Date", defaultValue="2941-10-12")
+    public void setEndDate(String endDate) {
+        this.endDate = endDate;
+    }
+
+    @StrutsTagAttribute(description="First available date in the calendar set", type="Date", defaultValue="1492-10-12")
+    public void setStartDate(String startDate) {
+        this.startDate = startDate;
+    }
+
+    @StrutsTagAttribute(description="Disable all incremental controls, must pick a date in the current display", type="Boolean", defaultValue="false")
+    public void setStaticDisplay(String staticDisplay) {
+        this.staticDisplay = staticDisplay;
+    }
+
+    @StrutsTagAttribute(description="Adjusts the first day of the week 0==Sunday..6==Saturday", type="Integer", defaultValue="0")
+    public void setWeekStartsOn(String weekStartsOn) {
+        this.weekStartsOn = weekStartsOn;
+    }
+
+    @StrutsTagAttribute(description="Language to display this widget in", defaultValue="brower's specified preferred language")
+    public void setLanguage(String language) {
+        this.language = language;
+    }
+    
+    @StrutsTagAttribute(description="A pattern used for the visual display of the formatted date, e.g. dd/MM/yyyy")
+    public void setDisplayFormat(String displayFormat) {
+        this.displayFormat = displayFormat;
+    }
+
+    @StrutsTagAttribute(description="Type of formatting used for visual display. Possible values are " +
+                "long, short, medium or full", defaultValue="short")
+    public void setFormatLength(String formatLength) {
+        this.formatLength = formatLength;
+    }
+
+    @StrutsTagAttribute(description="Path to icon used for the dropdown")
+    public void setIconPath(String iconPath) {
+        this.iconPath = iconPath;
+    }
+
+    @StrutsTagAttribute(description="Duration of toggle in milliseconds", type="Integer", defaultValue="100")
+    public void setToggleDuration(String toggleDuration) {
+        this.toggleDuration = toggleDuration;
+    }
+
+    @StrutsTagAttribute(description="Defines the type of the picker on the dropdown. Possible values are 'date'" +
+                " for a DateTimePicker, and 'time' for a timePicker", defaultValue="date")
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    @StrutsTagAttribute(description="oggle type of the dropdown. Possible values are plain,wipe,explode,fade", defaultValue="plain")
+    public void setToggleType(String toggleType) {
+        this.toggleType = toggleType;
+    }
+    
+    @StrutsTagAttribute(description="Template css path")
+    public void setTemplateCssPath(String templateCssPath) {
+        this.templateCssPath = templateCssPath;
+    }
+    
+    @StrutsTagAttribute(description="Preset the value of input element")
+    public void setValue(String arg0) {
+        super.setValue(arg0);
+    }
+    
+    @StrutsTagAttribute(description="Comma delimmited list of topics that will published when a value is selected")
+    public void setValueNotifyTopics(String valueNotifyTopics) {
+        this.valueNotifyTopics = valueNotifyTopics;
+    }
+    
+    private String format(Object obj) {
+        if(obj == null)
+            return null;
+
+        if(obj instanceof Date) {
+            return RFC3339_FORMAT.format((Date) obj);
+        } 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"))
+                return RFC3339_FORMAT.format(new Date());
+
+            
+            Date date = null;
+            //formats used to parse the date
+            List<DateFormat> formats = new ArrayList<DateFormat>();
+            formats.add(RFC3339_FORMAT);
+            formats.add(SimpleDateFormat.getTimeInstance(DateFormat.SHORT));
+            formats.add(SimpleDateFormat.getDateInstance(DateFormat.SHORT));
+            formats.add(SimpleDateFormat.getDateInstance(DateFormat.MEDIUM));
+            formats.add(SimpleDateFormat.getDateInstance(DateFormat.FULL));
+            formats.add(SimpleDateFormat.getDateInstance(DateFormat.LONG));
+            if (this.displayFormat != null) {
+                try {
+                    SimpleDateFormat displayFormat = new SimpleDateFormat(
+                        (String) getParameters().get("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) {
+                try {
+                    date = format.parse(dateStr);
+                    if (date != null)
+                        return RFC3339_FORMAT.format(date);
+                } catch (Exception e) {
+                    //keep going
+                }
+            }
+            
+           // last resource, assume already in correct/default format
+           if (LOG.isDebugEnabled())
+               LOG.debug("Unable to parse date " + dateStr);
+           return dateStr;
+        }
+    }
+
+}

Modified: struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Head.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Head.java?rev=569863&r1=569862&r2=569863&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Head.java (original)
+++ struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Head.java Sun Aug 26 12:18:15 2007
@@ -76,13 +76,17 @@
  * 
  * <p>The "locale" attribute configures Dojo's locale:</p>
  * 
- * "The locale Dojo uses on a page may be overridden by setting djConfig.locale. This may be 
+ * <p>"The locale Dojo uses on a page may be overridden by setting djConfig.locale. This may be 
  * done to accomodate applications with a known user profile or server pages which do manual
  * assembly and assume a certain locale. You may also set djConfig.extraLocale to load 
  * localizations in addition to your own, in case you want to specify a particular 
  * translation or have multiple languages appear on your page."</p>
  * 
- * <p>Dojo 0.4.2 is distributed with the Dojo plugin, to use a different Dojo version, the 
+ * <p>To improve loading time, the property "parseContent" is set to false by default. This property will
+ * instruct Dojo to only build widgets using specific element ids. If the property is set to true
+ * Dojo will scan the whole document looking for widgets.</p>
+ * 
+ * <p>Dojo 0.4.3 is distributed with the Dojo plugin, to use a different Dojo version, the 
  * "baseRelativePath" attribute can be set to the URL of the Dojo root folder on your application.
  * </p>
  * <!-- END SNIPPET: javadoc -->
@@ -113,13 +117,15 @@
 @StrutsTagSkipInheritance
 public class Head extends org.apache.struts2.components.Head {
     public static final String TEMPLATE = "head";
-
+    public static final String PARSE_CONTENT = "struts.dojo.head.parseContent";
+    
     private String debug;
     private String compressed;
     private String baseRelativePath;
     private String extraLocales;
     private String locale;
     private String cache;
+    private String parseContent;
     
     public Head(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
         super(stack, request, response);
@@ -146,6 +152,14 @@
             addParameter("locale", findString(this.locale));
         if (this.cache != null)
             addParameter("cache", findValue(this.cache, Boolean.class));
+        if (this.parseContent != null) {
+            Boolean shouldParseContent = (Boolean) findValue(this.parseContent, Boolean.class);
+            addParameter("parseContent", shouldParseContent);
+            stack.getContext().put(PARSE_CONTENT, shouldParseContent);
+        } else {
+            addParameter("parseContent", false);
+            stack.getContext().put(PARSE_CONTENT, false);
+        }
     }
 
     @Override
@@ -192,5 +206,10 @@
                 "the browser", defaultValue="true", type="Boolean")
     public void setCache(String cache) {
         this.cache = cache;
+    }
+    
+    @StrutsTagAttribute(description="Parse the whole document for widgets", defaultValue="false", type="Boolean")
+    public void setParseContent(String parseContent) {
+        this.parseContent = parseContent;
     }
 }

Modified: struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Submit.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Submit.java?rev=569863&r1=569862&r2=569863&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Submit.java (original)
+++ struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Submit.java Sun Aug 26 12:18:15 2007
@@ -1,466 +1,475 @@
-/*
- * $Id: Submit.java 508285 2007-02-16 02:42:24Z musachy $
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.struts2.dojo.components;
-
-import java.io.Writer;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.struts2.components.Form;
-import org.apache.struts2.components.FormButton;
-import org.apache.struts2.views.annotations.StrutsTag;
-import org.apache.struts2.views.annotations.StrutsTagAttribute;
-import org.apache.struts2.views.annotations.StrutsTagSkipInheritance;
-
-import com.opensymphony.xwork2.util.ValueStack;
-
-/**
- * <!-- START SNIPPET: javadoc -->
- * Renders a submit button that can submit a form asynchronously.
- * The submit can have three different types of rendering:
- * <ul>
- * <li>input: renders as html &lt;input type="submit"...&gt;</li>
- * <li>image: renders as html &lt;input type="image"...&gt;</li>
- * <li>button: renders as html &lt;button type="submit"...&gt;</li>
- * </ul>
- * Please note that the button type has advantages by adding the possibility to seperate the submitted value from the
- * text shown on the button face, but has issues with Microsoft Internet Explorer at least up to 6.0
- * <!-- END SNIPPET: javadoc -->
- *
- * <p>Examples</p>
- * <pre>
- * <!-- START SNIPPET: example1 -->
- * &lt;sx:submit value="%{'Submit'}" /&gt;
- * <!-- END SNIPPET: example1 -->
- * </pre>
- * <pre>
- * <!-- START SNIPPET: example2 -->
- * Render an image submit:
- * &lt;sx:submit type="image" value="%{'Submit'}" label="Submit the form" src="submit.gif"/&gt;
- * <!-- END SNIPPET: example2 -->
- * </pre>
- * <pre>
- * <!-- START SNIPPET: example3 -->
- * Render an button submit:
- * &lt;sx:submit type="button" value="%{'Submit'}" label="Submit the form"/&gt;
- * <!-- END SNIPPET: example3 -->
- * </pre>
- *
- * <!-- START SNIPPET: example4 -->
- * <p>Update target content with html returned from an action:</p>
- * <pre>
- * &lt;div id="div1"&gt;Div 1&lt;/div&gt;
- * &lt;s:url id="ajaxTest" value="/AjaxTest.action"/&gt;
- * 
- * &lt;sx:submit id="link1" href="%{ajaxTest}" target="div1" /&gt;
- * </pre>
- * <!-- END SNIPPET: example4 -->
- * 
- * <!-- START SNIPPET: example5 -->
- * <p>Submit form(inside the form):</p>
- * <pre>
- * &lt;s:form id="form" action="AjaxTest"&gt;
- *      &lt;input type="textbox" name="data"&gt;
- *      &lt;sx:submit /&gt;          
- * &lt;/s:form&gt;
- * </pre>
- * <!-- END SNIPPET: example5 -->
- * 
- * <!-- START SNIPPET: example6 -->
- * <p>Submit form(outside the form)</p>
- * <pre>
- * &lt;s:form id="form" action="AjaxTest"&gt;
- *      &lt;input type="textbox" name="data"&gt;   
- * &lt;/s:form&gt;
- * 
- * &lt;sx:submit formId="form" /&gt;
- * </pre>
- * <!-- END SNIPPET: example6 -->
- * 
- * <!-- START SNIPPET: example7 -->
- * <p>Using beforeNotifyTopics:</p>
- * <pre>
- * &lt;script type="text/javascript"&gt;
- * dojo.event.topic.subscribe("/before", function(event, widget){
- *     alert('inside a topic event. before request');
- *     //event: set event.cancel = true, to cancel request
- *     //widget: widget that published the topic
- * });
- * &lt;/script&gt;         
- * 
- * &lt;sx:submit beforeNotifyTopics="/before" /&gt;
- * </pre> 
- * <!-- END SNIPPET: example7 -->
- * 
- * <!-- START SNIPPET: example8 -->
- * <p>Using afterNotifyTopics and highlight target:</p>
- * <pre>
- * &lt;script type="text/javascript"&gt;
- * dojo.event.topic.subscribe("/after", function(data, request, widget){
- *     alert('inside a topic event. after request');
- *     //data : text returned from request(the html)
- *     //request: XMLHttpRequest object
- *     //widget: widget that published the topic
- * });
- * &lt;/script&gt;        
- * 
- * &lt;sx:submit afterNotifyTopics="/after" highlightColor="red" href="%{#ajaxTest}" /&gt;
- * </pre> 
- * <!-- END SNIPPET: example5 -->
- * 
- * <!-- START SNIPPET: example6 -->
- * <p>Using errorNotifyTopics and indicator:</p>
- * <pre>
- * &lt;script type="text/javascript"&gt;
- * dojo.event.topic.subscribe("/error", function(error, request, widget){
- *     alert('inside a topic event. on error');
- *     //error : error object (error.message has the error message)
- *     //request: XMLHttpRequest object
- *     //widget: widget that published the topic
- * });
- * &lt;/script&gt;         
- * 
- * &lt;img id="ind1" src="${pageContext.request.contextPath}/images/indicator.gif" style="display:none"/&gt;
- * &lt;sx:submit errorNotifyTopics="/error" indicator="ind1" href="%{#ajaxTest}" /&gt;
- * </pre> 
- * <!-- END SNIPPET: example6 -->
- */
-@StrutsTag(name="submit", tldTagClass="org.apache.struts2.dojo.views.jsp.ui.SubmitTag", description="Render a submit button")
-public class Submit extends FormButton implements RemoteBean {
-    
-    private static final Log LOG = LogFactory.getLog(Submit.class);
-    
-    final public static String TEMPLATE = "submit";
-
-    protected String href;
-    protected String errorText;
-    protected String executeScripts;
-    protected String loadingText;
-    protected String listenTopics;
-    protected String handler;
-    protected String formId;
-    protected String formFilter;
-    protected String src;
-    protected String notifyTopics;
-    protected String showErrorTransportText;
-    protected String indicator;
-    protected String showLoadingText;
-    protected String targets;
-    protected String beforeNotifyTopics;
-    protected String afterNotifyTopics;
-    protected String errorNotifyTopics;
-    protected String highlightColor;
-    protected String highlightDuration;
-    protected String validate;
-    protected String ajaxAfterValidation;
-    protected String separateScripts;
-    protected String transport;
-    protected String parseContent;
-    
-    public Submit(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
-        super(stack, request, response);
-    }
-
-    protected String getDefaultTemplate() {
-        return TEMPLATE;
-    }
-
-    public void evaluateParams() {
-        if ((key == null) && (value == null)) {
-            value = "Submit";
-        }
-
-        if (((key != null)) && (value == null)) {
-            this.value = "%{getText('"+key +"')}";
-        }
-
-        super.evaluateParams();
-    }
-
-    public void evaluateExtraParams() {
-        super.evaluateExtraParams();
-
-        if (href != null)
-            addParameter("href", findString(href));
-        if (errorText != null)
-            addParameter("errorText", findString(errorText));
-        if (loadingText != null)
-            addParameter("loadingText", findString(loadingText));
-        if (executeScripts != null)
-            addParameter("executeScripts", findValue(executeScripts, Boolean.class));
-        if (listenTopics != null)
-            addParameter("listenTopics", findString(listenTopics));
-        if (notifyTopics != null)
-            addParameter("notifyTopics", findString(notifyTopics));
-        if (handler != null)
-            addParameter("handler", findString(handler));
-        if (formId != null)
-            addParameter("formId", findString(formId));
-        if (formFilter != null)
-            addParameter("formFilter", findString(formFilter));
-        if (src != null)
-            addParameter("src", findString(src));
-        if (indicator != null)
-            addParameter("indicator", findString(indicator));
-        if (targets != null)
-            addParameter("targets", findString(targets));
-        if (showLoadingText != null)
-            addParameter("showLoadingText", findString(showLoadingText));
-        if (showLoadingText != null)
-            addParameter("showLoadingText", findString(showLoadingText));
-        if (beforeNotifyTopics != null)
-            addParameter("beforeNotifyTopics", findString(beforeNotifyTopics));
-        if (afterNotifyTopics != null)
-            addParameter("afterNotifyTopics", findString(afterNotifyTopics));
-        if (errorNotifyTopics != null)
-            addParameter("errorNotifyTopics", findString(errorNotifyTopics));
-        if (highlightColor != null)
-            addParameter("highlightColor", findString(highlightColor));
-        if (highlightDuration != null)
-            addParameter("highlightDuration", findString(highlightDuration));
-        if (separateScripts != null)
-            addParameter("separateScripts", findValue(separateScripts, Boolean.class));
-        if (transport != null)
-            addParameter("transport", findString(transport));
-        if (parseContent != null)
-            addParameter("parseContent", findValue(parseContent, Boolean.class));
-        
-        Boolean validateValue = false;
-        if (validate != null) {
-            validateValue = (Boolean) findValue(validate, Boolean.class);
-            addParameter("validate", validateValue);
-        } 
-        
-        Form form = (Form) findAncestor(Form.class);
-        if (form != null) 
-            addParameter("parentTheme", form.getTheme());
-        
-        if (ajaxAfterValidation != null)
-            addParameter("ajaxAfterValidation", findValue(ajaxAfterValidation, Boolean.class));
-    }
-
-    @Override
-    @StrutsTagSkipInheritance
-    public void setTheme(String theme) {
-        super.setTheme(theme);
-    }
-    
-    @Override
-    public String getTheme() {
-        return "ajax";
-    }
-    
-    /**
-     * Indicate whether the concrete button supports the type "image".
-     *
-     * @return <tt>true</tt> to indicate type image is supported.
-     */
-    protected boolean supportsImageType() {
-        return true;
-    }
-    
-    /**
-     * Overrides to be able to render body in a template rather than always before the template
-     */
-    public boolean end(Writer writer, String body) {
-        evaluateParams();
-        try {
-            addParameter("body", body);
-            
-            mergeTemplate(writer, buildTemplateName(template, getDefaultTemplate()));
-        } catch (Exception e) {
-            LOG.error("error when rendering", e);
-        }
-        finally {
-            popComponentStack();
-        }
-
-        return false;
-    }
-
-    @StrutsTagAttribute(description="Topic that will trigger the remote call")
-    public void setListenTopics(String listenTopics) {
-        this.listenTopics = listenTopics;
-    }
-
-    @StrutsTagAttribute(description="The URL to call to obtain the content. Note: If used with ajax context, the value must be set as an url tag value.")
-    public void setHref(String href) {
-        this.href = href;
-    }
-
-    @StrutsTagAttribute(description="The text to display to the user if the is an error fetching the content")
-    public void setErrorText(String errorText) {
-        this.errorText = errorText;
-    }
-
-    @StrutsTagAttribute(description="Javascript code in the fetched content will be executed", type="Boolean", defaultValue="false")
-    public void setExecuteScripts(String executeScripts) {
-        this.executeScripts = executeScripts;
-    }
-
-    @StrutsTagAttribute(description="Text to be shown while content is being fetched", defaultValue="Loading...")
-    public void setLoadingText(String loadingText) {
-        this.loadingText = loadingText;
-    }
-
-    @StrutsTagAttribute(description="Javascript function name that will make the request")
-    public void setHandler(String handler) {
-        this.handler = handler;
-    }
-
-    @StrutsTagAttribute(description="Function name used to filter the fields of the form.")
-    public void setFormFilter(String formFilter) {
-        this.formFilter = formFilter;
-    }
-
-    @StrutsTagAttribute(description="Form id whose fields will be serialized and passed as parameters")
-    public void setFormId(String formId) {
-        this.formId = formId;
-    }
-
-    @StrutsTagAttribute(description="Supply an image src for <i>image</i> type submit button. Will have no effect for types <i>input</i> and <i>button</i>.")
-    public void setSrc(String src) {
-        this.src = src;
-    }
-
-    @StrutsTagAttribute(description="Comma delimited list of ids of the elements whose content will be updated")
-    public void setTargets(String targets) {
-        this.targets = targets;
-    }
-
-    @StrutsTagAttribute(description="Comma delimmited list of topics that will published before and after the request, and on errors")
-    public void setNotifyTopics(String notifyTopics) {
-        this.notifyTopics = notifyTopics;
-    }
-
-    @StrutsTagAttribute(description="Set whether errors will be shown or not", type="Boolean", defaultValue="true")
-    public void setShowErrorTransportText(String showErrorTransportText) {
-        this.showErrorTransportText = showErrorTransportText;
-    }
-
-    @StrutsTagAttribute(description="Set indicator")
-    public void setIndicator(String indicator) {
-        this.indicator = indicator;
-    }
-
-    @StrutsTagAttribute(description="Show loading text on targets", type="Boolean", defaultValue="false")
-    public void setShowLoadingText(String showLoadingText) {
-        this.showLoadingText = showLoadingText;
-    }
-    
-    @StrutsTagAttribute(description="The css class to use for element")
-    public void setCssClass(String cssClass) {
-        super.setCssClass(cssClass);
-    }
-
-    @StrutsTagAttribute(description="The css style to use for element")
-    public void setCssStyle(String cssStyle) {
-        super.setCssStyle(cssStyle);
-    }
-
-    @StrutsTagAttribute(description="The id to use for the element")
-    public void setId(String id) {
-        super.setId(id);
-    }
-
-    @StrutsTagAttribute(description="The name to set for element")
-    public void setName(String name) {
-        super.setName(name);
-    }
-
-    @StrutsTagAttribute(description="The type of submit to use. Valid values are <i>input</i>, " +
-        "<i>button</i> and <i>image</i>.", defaultValue="input")
-    public void setType(String type) {
-        super.setType(type);
-    }
-
-    @StrutsTagAttribute(description="Preset the value of input element.")
-    public void setValue(String value) {
-        super.setValue(value);
-    }
-
-    @StrutsTagAttribute(description="Label expression used for rendering a element specific label")
-    public void setLabel(String label) {
-        super.setLabel(label);
-    }
-    
-    @StrutsTagAttribute(description="Comma delimmited list of topics that will published after the request(if the request succeeds)")
-    public void setAfterNotifyTopics(String afterNotifyTopics) {
-        this.afterNotifyTopics = afterNotifyTopics;
-    }
-
-    @StrutsTagAttribute(description="Comma delimmited list of topics that will published before the request")
-    public void setBeforeNotifyTopics(String beforeNotifyTopics) {
-        this.beforeNotifyTopics = beforeNotifyTopics;
-    }
-
-    @StrutsTagAttribute(description="Comma delimmited list of topics that will published after the request(if the request fails)")
-    public void setErrorNotifyTopics(String errorNotifyTopics) {
-        this.errorNotifyTopics = errorNotifyTopics;
-    }
-    
-    @StrutsTagAttribute(description = "Color used to perform a highlight effect on the elements specified in the 'targets' attribute", 
-        defaultValue = "none")
-    public void setHighlightColor(String highlightColor) {
-        this.highlightColor = highlightColor;
-    }
-
-    @StrutsTagAttribute(description = "Duration of highlight effect in milliseconds. Only valid if 'highlightColor' attribute is set", 
-        defaultValue = "1000")
-    public void setHighlightDuration(String highlightDuration) {
-        this.highlightDuration = highlightDuration;
-    }
-
-    @StrutsTagAttribute(description = "Perform Ajax calidation. 'ajaxValidation' interceptor must be applied to action", type="Boolean", 
-        defaultValue = "false")
-    public void setValidate(String validate) {
-        this.validate = validate;
-    }
-
-    @StrutsTagAttribute(description = "Make an asynchronous request if validation succeeds. Only valid if 'validate' is 'true'", type="Boolean", 
-        defaultValue = "false")
-    public void setAjaxAfterValidation(String ajaxAfterValidation) {
-        this.ajaxAfterValidation = ajaxAfterValidation;
-    }
-
-    @StrutsTagSkipInheritance
-    public void setAction(String action) {
-        super.setAction(action);
-    }
-    
-    @StrutsTagAttribute(description="Run scripts in a separate scope, unique for each tag", defaultValue="true")
-    public void setSeparateScripts(String separateScripts) {
-        this.separateScripts = separateScripts;
-    }
-    
-    @StrutsTagAttribute(description="Transport used by Dojo to make the request", defaultValue="XMLHTTPTransport")
-    public void setTransport(String transport) {
-        this.transport = transport;
-    }
-    
-    @StrutsTagAttribute(description="Parse returned HTML for Dojo widgets", defaultValue="true", type="Boolean")
-    public void setParseContent(String parseContent) {
-        this.parseContent = parseContent;
-    }
-}
+/*
+ * $Id: Submit.java 508285 2007-02-16 02:42:24Z musachy $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.struts2.dojo.components;
+
+import java.io.Writer;
+import java.util.Random;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.struts2.components.Form;
+import org.apache.struts2.components.FormButton;
+import org.apache.struts2.views.annotations.StrutsTag;
+import org.apache.struts2.views.annotations.StrutsTagAttribute;
+import org.apache.struts2.views.annotations.StrutsTagSkipInheritance;
+
+import com.opensymphony.xwork2.util.ValueStack;
+
+/**
+ * <!-- START SNIPPET: javadoc -->
+ * Renders a submit button that can submit a form asynchronously.
+ * The submit can have three different types of rendering:
+ * <ul>
+ * <li>input: renders as html &lt;input type="submit"...&gt;</li>
+ * <li>image: renders as html &lt;input type="image"...&gt;</li>
+ * <li>button: renders as html &lt;button type="submit"...&gt;</li>
+ * </ul>
+ * Please note that the button type has advantages by adding the possibility to seperate the submitted value from the
+ * text shown on the button face, but has issues with Microsoft Internet Explorer at least up to 6.0
+ * <!-- END SNIPPET: javadoc -->
+ *
+ * <p>Examples</p>
+ * <pre>
+ * <!-- START SNIPPET: example1 -->
+ * &lt;sx:submit value="%{'Submit'}" /&gt;
+ * <!-- END SNIPPET: example1 -->
+ * </pre>
+ * <pre>
+ * <!-- START SNIPPET: example2 -->
+ * Render an image submit:
+ * &lt;sx:submit type="image" value="%{'Submit'}" label="Submit the form" src="submit.gif"/&gt;
+ * <!-- END SNIPPET: example2 -->
+ * </pre>
+ * <pre>
+ * <!-- START SNIPPET: example3 -->
+ * Render an button submit:
+ * &lt;sx:submit type="button" value="%{'Submit'}" label="Submit the form"/&gt;
+ * <!-- END SNIPPET: example3 -->
+ * </pre>
+ *
+ * <!-- START SNIPPET: example4 -->
+ * <p>Update target content with html returned from an action:</p>
+ * <pre>
+ * &lt;div id="div1"&gt;Div 1&lt;/div&gt;
+ * &lt;s:url id="ajaxTest" value="/AjaxTest.action"/&gt;
+ * 
+ * &lt;sx:submit id="link1" href="%{ajaxTest}" target="div1" /&gt;
+ * </pre>
+ * <!-- END SNIPPET: example4 -->
+ * 
+ * <!-- START SNIPPET: example5 -->
+ * <p>Submit form(inside the form):</p>
+ * <pre>
+ * &lt;s:form id="form" action="AjaxTest"&gt;
+ *      &lt;input type="textbox" name="data"&gt;
+ *      &lt;sx:submit /&gt;          
+ * &lt;/s:form&gt;
+ * </pre>
+ * <!-- END SNIPPET: example5 -->
+ * 
+ * <!-- START SNIPPET: example6 -->
+ * <p>Submit form(outside the form)</p>
+ * <pre>
+ * &lt;s:form id="form" action="AjaxTest"&gt;
+ *      &lt;input type="textbox" name="data"&gt;   
+ * &lt;/s:form&gt;
+ * 
+ * &lt;sx:submit formId="form" /&gt;
+ * </pre>
+ * <!-- END SNIPPET: example6 -->
+ * 
+ * <!-- START SNIPPET: example7 -->
+ * <p>Using beforeNotifyTopics:</p>
+ * <pre>
+ * &lt;script type="text/javascript"&gt;
+ * dojo.event.topic.subscribe("/before", function(event, widget){
+ *     alert('inside a topic event. before request');
+ *     //event: set event.cancel = true, to cancel request
+ *     //widget: widget that published the topic
+ * });
+ * &lt;/script&gt;         
+ * 
+ * &lt;sx:submit beforeNotifyTopics="/before" /&gt;
+ * </pre> 
+ * <!-- END SNIPPET: example7 -->
+ * 
+ * <!-- START SNIPPET: example8 -->
+ * <p>Using afterNotifyTopics and highlight target:</p>
+ * <pre>
+ * &lt;script type="text/javascript"&gt;
+ * dojo.event.topic.subscribe("/after", function(data, request, widget){
+ *     alert('inside a topic event. after request');
+ *     //data : text returned from request(the html)
+ *     //request: XMLHttpRequest object
+ *     //widget: widget that published the topic
+ * });
+ * &lt;/script&gt;        
+ * 
+ * &lt;sx:submit afterNotifyTopics="/after" highlightColor="red" href="%{#ajaxTest}" /&gt;
+ * </pre> 
+ * <!-- END SNIPPET: example5 -->
+ * 
+ * <!-- START SNIPPET: example6 -->
+ * <p>Using errorNotifyTopics and indicator:</p>
+ * <pre>
+ * &lt;script type="text/javascript"&gt;
+ * dojo.event.topic.subscribe("/error", function(error, request, widget){
+ *     alert('inside a topic event. on error');
+ *     //error : error object (error.message has the error message)
+ *     //request: XMLHttpRequest object
+ *     //widget: widget that published the topic
+ * });
+ * &lt;/script&gt;         
+ * 
+ * &lt;img id="ind1" src="${pageContext.request.contextPath}/images/indicator.gif" style="display:none"/&gt;
+ * &lt;sx:submit errorNotifyTopics="/error" indicator="ind1" href="%{#ajaxTest}" /&gt;
+ * </pre> 
+ * <!-- END SNIPPET: example6 -->
+ */
+@StrutsTag(name="submit", tldTagClass="org.apache.struts2.dojo.views.jsp.ui.SubmitTag", description="Render a submit button")
+public class Submit extends FormButton implements RemoteBean {
+    
+    private static final Log LOG = LogFactory.getLog(Submit.class);
+    
+    final public static String TEMPLATE = "submit";
+
+    protected String href;
+    protected String errorText;
+    protected String executeScripts;
+    protected String loadingText;
+    protected String listenTopics;
+    protected String handler;
+    protected String formId;
+    protected String formFilter;
+    protected String src;
+    protected String notifyTopics;
+    protected String showErrorTransportText;
+    protected String indicator;
+    protected String showLoadingText;
+    protected String targets;
+    protected String beforeNotifyTopics;
+    protected String afterNotifyTopics;
+    protected String errorNotifyTopics;
+    protected String highlightColor;
+    protected String highlightDuration;
+    protected String validate;
+    protected String ajaxAfterValidation;
+    protected String separateScripts;
+    protected String transport;
+    protected String parseContent;
+    
+    public Submit(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
+        super(stack, request, response);
+    }
+
+    protected String getDefaultTemplate() {
+        return TEMPLATE;
+    }
+
+    public void evaluateParams() {
+        if ((key == null) && (value == null)) {
+            value = "Submit";
+        }
+
+        if (((key != null)) && (value == null)) {
+            this.value = "%{getText('"+key +"')}";
+        }
+
+        super.evaluateParams();
+    }
+
+    public void evaluateExtraParams() {
+        super.evaluateExtraParams();
+
+        if (href != null)
+            addParameter("href", findString(href));
+        if (errorText != null)
+            addParameter("errorText", findString(errorText));
+        if (loadingText != null)
+            addParameter("loadingText", findString(loadingText));
+        if (executeScripts != null)
+            addParameter("executeScripts", findValue(executeScripts, Boolean.class));
+        if (listenTopics != null)
+            addParameter("listenTopics", findString(listenTopics));
+        if (notifyTopics != null)
+            addParameter("notifyTopics", findString(notifyTopics));
+        if (handler != null)
+            addParameter("handler", findString(handler));
+        if (formId != null)
+            addParameter("formId", findString(formId));
+        if (formFilter != null)
+            addParameter("formFilter", findString(formFilter));
+        if (src != null)
+            addParameter("src", findString(src));
+        if (indicator != null)
+            addParameter("indicator", findString(indicator));
+        if (targets != null)
+            addParameter("targets", findString(targets));
+        if (showLoadingText != null)
+            addParameter("showLoadingText", findString(showLoadingText));
+        if (showLoadingText != null)
+            addParameter("showLoadingText", findString(showLoadingText));
+        if (beforeNotifyTopics != null)
+            addParameter("beforeNotifyTopics", findString(beforeNotifyTopics));
+        if (afterNotifyTopics != null)
+            addParameter("afterNotifyTopics", findString(afterNotifyTopics));
+        if (errorNotifyTopics != null)
+            addParameter("errorNotifyTopics", findString(errorNotifyTopics));
+        if (highlightColor != null)
+            addParameter("highlightColor", findString(highlightColor));
+        if (highlightDuration != null)
+            addParameter("highlightDuration", findString(highlightDuration));
+        if (separateScripts != null)
+            addParameter("separateScripts", findValue(separateScripts, Boolean.class));
+        if (transport != null)
+            addParameter("transport", findString(transport));
+        if (parseContent != null)
+            addParameter("parseContent", findValue(parseContent, Boolean.class));
+        
+        Boolean validateValue = false;
+        if (validate != null) {
+            validateValue = (Boolean) findValue(validate, Boolean.class);
+            addParameter("validate", validateValue);
+        } 
+        
+        Form form = (Form) findAncestor(Form.class);
+        if (form != null) 
+            addParameter("parentTheme", form.getTheme());
+        
+        if (ajaxAfterValidation != null)
+            addParameter("ajaxAfterValidation", findValue(ajaxAfterValidation, Boolean.class));
+        
+        boolean generateId = !(Boolean)stack.getContext().get(Head.PARSE_CONTENT);
+        addParameter("pushId", generateId);
+        if ((this.id == null || this.id.length() == 0) && generateId) {
+            Random random = new Random();
+            this.id = "widget_" + Math.abs(random.nextInt());
+            addParameter("id", this.id);
+        }
+    }
+
+    @Override
+    @StrutsTagSkipInheritance
+    public void setTheme(String theme) {
+        super.setTheme(theme);
+    }
+    
+    @Override
+    public String getTheme() {
+        return "ajax";
+    }
+    
+    /**
+     * Indicate whether the concrete button supports the type "image".
+     *
+     * @return <tt>true</tt> to indicate type image is supported.
+     */
+    protected boolean supportsImageType() {
+        return true;
+    }
+    
+    /**
+     * Overrides to be able to render body in a template rather than always before the template
+     */
+    public boolean end(Writer writer, String body) {
+        evaluateParams();
+        try {
+            addParameter("body", body);
+            
+            mergeTemplate(writer, buildTemplateName(template, getDefaultTemplate()));
+        } catch (Exception e) {
+            LOG.error("error when rendering", e);
+        }
+        finally {
+            popComponentStack();
+        }
+
+        return false;
+    }
+
+    @StrutsTagAttribute(description="Topic that will trigger the remote call")
+    public void setListenTopics(String listenTopics) {
+        this.listenTopics = listenTopics;
+    }
+
+    @StrutsTagAttribute(description="The URL to call to obtain the content. Note: If used with ajax context, the value must be set as an url tag value.")
+    public void setHref(String href) {
+        this.href = href;
+    }
+
+    @StrutsTagAttribute(description="The text to display to the user if the is an error fetching the content")
+    public void setErrorText(String errorText) {
+        this.errorText = errorText;
+    }
+
+    @StrutsTagAttribute(description="Javascript code in the fetched content will be executed", type="Boolean", defaultValue="false")
+    public void setExecuteScripts(String executeScripts) {
+        this.executeScripts = executeScripts;
+    }
+
+    @StrutsTagAttribute(description="Text to be shown while content is being fetched", defaultValue="Loading...")
+    public void setLoadingText(String loadingText) {
+        this.loadingText = loadingText;
+    }
+
+    @StrutsTagAttribute(description="Javascript function name that will make the request")
+    public void setHandler(String handler) {
+        this.handler = handler;
+    }
+
+    @StrutsTagAttribute(description="Function name used to filter the fields of the form.")
+    public void setFormFilter(String formFilter) {
+        this.formFilter = formFilter;
+    }
+
+    @StrutsTagAttribute(description="Form id whose fields will be serialized and passed as parameters")
+    public void setFormId(String formId) {
+        this.formId = formId;
+    }
+
+    @StrutsTagAttribute(description="Supply an image src for <i>image</i> type submit button. Will have no effect for types <i>input</i> and <i>button</i>.")
+    public void setSrc(String src) {
+        this.src = src;
+    }
+
+    @StrutsTagAttribute(description="Comma delimited list of ids of the elements whose content will be updated")
+    public void setTargets(String targets) {
+        this.targets = targets;
+    }
+
+    @StrutsTagAttribute(description="Comma delimmited list of topics that will published before and after the request, and on errors")
+    public void setNotifyTopics(String notifyTopics) {
+        this.notifyTopics = notifyTopics;
+    }
+
+    @StrutsTagAttribute(description="Set whether errors will be shown or not", type="Boolean", defaultValue="true")
+    public void setShowErrorTransportText(String showErrorTransportText) {
+        this.showErrorTransportText = showErrorTransportText;
+    }
+
+    @StrutsTagAttribute(description="Set indicator")
+    public void setIndicator(String indicator) {
+        this.indicator = indicator;
+    }
+
+    @StrutsTagAttribute(description="Show loading text on targets", type="Boolean", defaultValue="false")
+    public void setShowLoadingText(String showLoadingText) {
+        this.showLoadingText = showLoadingText;
+    }
+    
+    @StrutsTagAttribute(description="The css class to use for element")
+    public void setCssClass(String cssClass) {
+        super.setCssClass(cssClass);
+    }
+
+    @StrutsTagAttribute(description="The css style to use for element")
+    public void setCssStyle(String cssStyle) {
+        super.setCssStyle(cssStyle);
+    }
+
+    @StrutsTagAttribute(description="The id to use for the element")
+    public void setId(String id) {
+        super.setId(id);
+    }
+
+    @StrutsTagAttribute(description="The name to set for element")
+    public void setName(String name) {
+        super.setName(name);
+    }
+
+    @StrutsTagAttribute(description="The type of submit to use. Valid values are <i>input</i>, " +
+        "<i>button</i> and <i>image</i>.", defaultValue="input")
+    public void setType(String type) {
+        super.setType(type);
+    }
+
+    @StrutsTagAttribute(description="Preset the value of input element.")
+    public void setValue(String value) {
+        super.setValue(value);
+    }
+
+    @StrutsTagAttribute(description="Label expression used for rendering a element specific label")
+    public void setLabel(String label) {
+        super.setLabel(label);
+    }
+    
+    @StrutsTagAttribute(description="Comma delimmited list of topics that will published after the request(if the request succeeds)")
+    public void setAfterNotifyTopics(String afterNotifyTopics) {
+        this.afterNotifyTopics = afterNotifyTopics;
+    }
+
+    @StrutsTagAttribute(description="Comma delimmited list of topics that will published before the request")
+    public void setBeforeNotifyTopics(String beforeNotifyTopics) {
+        this.beforeNotifyTopics = beforeNotifyTopics;
+    }
+
+    @StrutsTagAttribute(description="Comma delimmited list of topics that will published after the request(if the request fails)")
+    public void setErrorNotifyTopics(String errorNotifyTopics) {
+        this.errorNotifyTopics = errorNotifyTopics;
+    }
+    
+    @StrutsTagAttribute(description = "Color used to perform a highlight effect on the elements specified in the 'targets' attribute", 
+        defaultValue = "none")
+    public void setHighlightColor(String highlightColor) {
+        this.highlightColor = highlightColor;
+    }
+
+    @StrutsTagAttribute(description = "Duration of highlight effect in milliseconds. Only valid if 'highlightColor' attribute is set", 
+        defaultValue = "1000")
+    public void setHighlightDuration(String highlightDuration) {
+        this.highlightDuration = highlightDuration;
+    }
+
+    @StrutsTagAttribute(description = "Perform Ajax calidation. 'ajaxValidation' interceptor must be applied to action", type="Boolean", 
+        defaultValue = "false")
+    public void setValidate(String validate) {
+        this.validate = validate;
+    }
+
+    @StrutsTagAttribute(description = "Make an asynchronous request if validation succeeds. Only valid if 'validate' is 'true'", type="Boolean", 
+        defaultValue = "false")
+    public void setAjaxAfterValidation(String ajaxAfterValidation) {
+        this.ajaxAfterValidation = ajaxAfterValidation;
+    }
+
+    @StrutsTagSkipInheritance
+    public void setAction(String action) {
+        super.setAction(action);
+    }
+    
+    @StrutsTagAttribute(description="Run scripts in a separate scope, unique for each tag", defaultValue="true")
+    public void setSeparateScripts(String separateScripts) {
+        this.separateScripts = separateScripts;
+    }
+    
+    @StrutsTagAttribute(description="Transport used by Dojo to make the request", defaultValue="XMLHTTPTransport")
+    public void setTransport(String transport) {
+        this.transport = transport;
+    }
+    
+    @StrutsTagAttribute(description="Parse returned HTML for Dojo widgets", defaultValue="true", type="Boolean")
+    public void setParseContent(String parseContent) {
+        this.parseContent = parseContent;
+    }
+}