Author: roughley
Date: Sun Feb 11 12:31:09 2007
New Revision: 506121

URL: http://svn.apache.org/viewvc?view=rev&rev=506121
Log:
Changed converter so that it extended the StrutsTypeConverter (and is used in 
the example application).  Modified the Index action so that it uses the 
converter to provide a date compatible with the HelloWorldAction 

Modified:
    
struts/maven/trunk/struts2-archetype-starter/src/main/resources/archetype-resources/src/main/java/DateConverter.java
    
struts/maven/trunk/struts2-archetype-starter/src/main/resources/archetype-resources/src/main/java/IndexAction.java

Modified: 
struts/maven/trunk/struts2-archetype-starter/src/main/resources/archetype-resources/src/main/java/DateConverter.java
URL: 
http://svn.apache.org/viewvc/struts/maven/trunk/struts2-archetype-starter/src/main/resources/archetype-resources/src/main/java/DateConverter.java?view=diff&rev=506121&r1=506120&r2=506121
==============================================================================
--- 
struts/maven/trunk/struts2-archetype-starter/src/main/resources/archetype-resources/src/main/java/DateConverter.java
 (original)
+++ 
struts/maven/trunk/struts2-archetype-starter/src/main/resources/archetype-resources/src/main/java/DateConverter.java
 Sun Feb 11 12:31:09 2007
@@ -23,27 +23,27 @@
 import java.text.ParseException;
 import java.util.Map;
 import java.util.Date;
+import com.opensymphony.xwork2.util.TypeConversionException;
 
 /**
  * 
  */
-public class DateConverter {
+public class DateConverter extends StrutsTypeConverter {
     public Object convertFromString(Map context, String[] values, Class 
toClass) {
         if (values != null && values.length > 0 && values[0] != null && 
values[0].length() > 0) {
-            SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
             try {
                 return sdf.parse(values[0]);
             }
             catch(ParseException e) {
-                e.printStackTrace();
-                return "";
+                throw new TypeConversionException(e);
             }
         }
         return null;
     }
     public String convertToString(Map context, Object o) {
         if (o instanceof Date) {
-            SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
             return sdf.format((Date)o);
         }
         return "";

Modified: 
struts/maven/trunk/struts2-archetype-starter/src/main/resources/archetype-resources/src/main/java/IndexAction.java
URL: 
http://svn.apache.org/viewvc/struts/maven/trunk/struts2-archetype-starter/src/main/resources/archetype-resources/src/main/java/IndexAction.java?view=diff&rev=506121&r1=506120&r2=506121
==============================================================================
--- 
struts/maven/trunk/struts2-archetype-starter/src/main/resources/archetype-resources/src/main/java/IndexAction.java
 (original)
+++ 
struts/maven/trunk/struts2-archetype-starter/src/main/resources/archetype-resources/src/main/java/IndexAction.java
 Sun Feb 11 12:31:09 2007
@@ -19,14 +19,18 @@
 
 import com.opensymphony.xwork2.ActionSupport;
 import java.util.Date;
+import com.opensymphony.xwork2.conversion.annotations.Conversion;
+import com.opensymphony.xwork2.conversion.annotations.TypeConversion;
 
 /**
  * 
  */
[EMAIL PROTECTED]()
 public class IndexAction extends ActionSupport {
     
     private Date now = new Date(System.currentTimeMillis());
     
+    @TypeConversion(converter = "com.fdar.apress.s2.DateConverter")
     public Date getDateNow() { return now; }
     
     public String execute() throws Exception {


Reply via email to