incubator-adffaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awi...@apache.org
Subject svn commit: r429948 - in /incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo: composite/DateField.java composite/DateFieldAsRenderer.java webapp/SourceCodeServlet.java
Date Wed, 09 Aug 2006 03:24:43 GMT
Author: awiner
Date: Tue Aug  8 20:24:42 2006
New Revision: 429948

URL: http://svn.apache.org/viewvc?rev=429948&view=rev
Log:
Fix Java 5 warnings

Modified:
    incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateField.java
    incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldAsRenderer.java
    incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/webapp/SourceCodeServlet.java

Modified: incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateField.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateField.java?rev=429948&r1=429947&r2=429948&view=diff
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateField.java
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateField.java
Tue Aug  8 20:24:42 2006
@@ -17,6 +17,7 @@
 
 import java.io.IOException;
 
+import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 
@@ -89,17 +90,19 @@
     int day = ((Number) _day.getValue()).intValue();
 
     Date oldValue = (Date) getValue();
-    Date newValue = (Date) oldValue.clone();
-    newValue.setYear(year);
-    newValue.setMonth(month);
-    newValue.setDate(day);
+    Calendar calendar = Calendar.getInstance();
+    calendar.setLenient(true);
+    calendar.setTime(oldValue);
+    calendar.set(Calendar.YEAR, year);
+    calendar.set(Calendar.MONTH, month);
+    calendar.set(Calendar.DAY_OF_MONTH, day);
 
     //=-=AEW RUN VALIDATORS!
 
     // Invalid day given the month
-    if (day != newValue.getDate())
+    if (day != calendar.get(Calendar.DAY_OF_MONTH))
     {
-      int numberOfDaysInMonth = day - newValue.getDate();
+      int numberOfDaysInMonth = day - calendar.get(Calendar.DAY_OF_MONTH);
       FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
                     "Invalid date.",
                     "This month only has " + numberOfDaysInMonth + " days!");
@@ -113,7 +116,8 @@
 
       // And if the value actually changed, store it and send a value change
       // event.
-      if (!newValue.equals(oldValue))
+      Date newValue = calendar.getTime();
+      if (!calendar.getTime().equals(oldValue))
       {
         setValue(newValue);
         queueEvent(new ValueChangeEvent(this, oldValue, newValue));
@@ -148,6 +152,7 @@
     return true;
   }
 
+  @SuppressWarnings("unchecked")
   private void _addChildren(FacesContext context)
   {
     if (_month != null)
@@ -157,6 +162,13 @@
     children.clear();
 
     Date value = (Date) getValue();
+    Calendar calendar = null;
+    if(value != null)
+    {
+      calendar = Calendar.getInstance();
+      calendar.setLenient(true);
+      calendar.setTime(value);
+    }
 
     // A proper implementation would add children in the correct
     // order for the current locale
@@ -168,7 +180,7 @@
     monthRange.setMaximum(12);
     _month.addValidator(monthRange);
     if (value != null)
-      _month.setValue(new Integer(value.getMonth() + 1));
+      _month.setValue(new Integer(calendar.get(Calendar.MONTH) + 1));
 
     _day = _createTwoDigitInput(context);
     _day.setId("day");
@@ -178,14 +190,14 @@
     dayRange.setMaximum(31);
     _day.addValidator(dayRange);
     if (value != null)
-      _day.setValue(new Integer(value.getDate()));
+      _day.setValue(new Integer(calendar.get(Calendar.DAY_OF_MONTH)));
 
     _year = _createTwoDigitInput(context);
     _year.setId("year");
     _year.setShortDesc("Year");
     if (value != null)
     {
-      int yearValue = value.getYear();
+      int yearValue = calendar.get(Calendar.YEAR) - 1900;
       if (yearValue >= 100)
         yearValue -= 100;
       _year.setValue(new Integer(yearValue));

Modified: incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldAsRenderer.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldAsRenderer.java?rev=429948&r1=429947&r2=429948&view=diff
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldAsRenderer.java
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldAsRenderer.java
Tue Aug  8 20:24:42 2006
@@ -16,7 +16,7 @@
 package org.apache.myfaces.trinidaddemo.composite;
 
 import java.io.IOException;
-
+import java.util.Calendar;
 import java.util.Date;
 import java.util.Map;
 
@@ -104,22 +104,25 @@
     int day = ((Number) dayComp.getValue()).intValue();
 
     Date oldValue = (Date) ((EditableValueHolder) component).getValue();
-    Date newValue = (Date) oldValue.clone();
-    newValue.setYear(year);
-    newValue.setMonth(month);
-    newValue.setDate(day);
-
+    //Date newValue = (Date) oldValue.clone();
+    Calendar calendar = Calendar.getInstance();
+    calendar.setLenient(true);
+    calendar.setTime(oldValue);
+    calendar.set(Calendar.YEAR, year);
+    calendar.set(Calendar.MONTH, month);
+    calendar.set(Calendar.DAY_OF_MONTH, day);
+    
     // Invalid day given the month
-    if (day != newValue.getDate())
+    if (day != calendar.get(Calendar.DAY_OF_MONTH))
     {
-      int numberOfDaysInMonth = day - newValue.getDate();
+      int numberOfDaysInMonth = day - calendar.get(Calendar.DAY_OF_MONTH);
       FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
                     "Invalid date.",
                     "This month only has " + numberOfDaysInMonth + " days!");
       throw new ConverterException(message);
     }
 
-    return newValue;
+    return calendar.getTime();
   }
 
   @Override
@@ -179,6 +182,13 @@
     facets.clear();
 
     Date value = (Date) ((EditableValueHolder) component).getValue();
+    Calendar calendar = null;
+    if(value != null)
+    {
+      calendar = Calendar.getInstance();
+      calendar.setLenient(true);
+      calendar.setTime(value);
+    }
 
     CoreInputText month = _createTwoDigitInput(context);
     month.setShortDesc("Month");
@@ -189,7 +199,7 @@
     monthRange.setMaximum(12);
     month.addValidator(monthRange);
     if (value != null)
-      month.setValue(new Integer(value.getMonth() + 1));
+      month.setValue(new Integer(calendar.get(Calendar.MONTH) + 1));
     facets.put("month", month);
 
     CoreInputText day = _createTwoDigitInput(context);
@@ -200,7 +210,7 @@
     dayRange.setMaximum(31);
     day.addValidator(dayRange);
     if (value != null)
-      day.setValue(new Integer(value.getDate()));
+      day.setValue(new Integer(calendar.get(Calendar.DAY_OF_MONTH)));
     facets.put("day", day);
 
     CoreInputText year = _createTwoDigitInput(context);
@@ -208,7 +218,7 @@
     year.setId(id + "_year");
     if (value != null)
     {
-      int yearValue = value.getYear();
+      int yearValue = calendar.get(Calendar.YEAR) - 1900;
       if (yearValue >= 100)
         yearValue -= 100;
       year.setValue(new Integer(yearValue));

Modified: incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/webapp/SourceCodeServlet.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/webapp/SourceCodeServlet.java?rev=429948&r1=429947&r2=429948&view=diff
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/webapp/SourceCodeServlet.java
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/webapp/SourceCodeServlet.java
Tue Aug  8 20:24:42 2006
@@ -30,6 +30,7 @@
 
 public class SourceCodeServlet extends HttpServlet
 {
+  @Override
   public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException,
ServletException
   {
   String webPage = req.getServletPath();



Mime
View raw message