[richfaces-svn-commits] JBoss Rich Faces SVN: r3174 - in branches/3.1.x/ui/calendar/src/main: java/org/richfaces/component and 1 other directory.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Mon Oct 1 09:15:48 EDT 2007


Author: akushunin
Date: 2007-10-01 09:15:48 -0400 (Mon, 01 Oct 2007)
New Revision: 3174

Modified:
   branches/3.1.x/ui/calendar/src/main/config/component/calendar.xml
   branches/3.1.x/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java
Log:
RF-1028

Modified: branches/3.1.x/ui/calendar/src/main/config/component/calendar.xml
===================================================================
--- branches/3.1.x/ui/calendar/src/main/config/component/calendar.xml	2007-10-01 13:12:23 UTC (rev 3173)
+++ branches/3.1.x/ui/calendar/src/main/config/component/calendar.xml	2007-10-01 13:15:48 UTC (rev 3174)
@@ -111,10 +111,7 @@
 		<property elonly="true">
 			<name>currentDate</name>
 			<classname>java.util.Date</classname>
-			<description>Defines current date</description>
-			<defaultvalue>
-				java.util.Calendar.getInstance(getTimeZone()).getTime()
-			</defaultvalue>
+			<description>Defines current date</description>			
 		</property>
 		<property>
 			<name>currentDateChangeListener</name>

Modified: branches/3.1.x/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java
===================================================================
--- branches/3.1.x/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java	2007-10-01 13:12:23 UTC (rev 3173)
+++ branches/3.1.x/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java	2007-10-01 13:15:48 UTC (rev 3174)
@@ -29,6 +29,7 @@
 import java.util.Locale;
 import java.util.TimeZone;
 
+import javax.faces.FacesException;
 import javax.faces.application.FacesMessage;
 import javax.faces.component.UIInput;
 import javax.faces.component.UIViewRoot;
@@ -38,15 +39,12 @@
 import javax.faces.el.MethodBinding;
 import javax.faces.el.ValueBinding;
 import javax.faces.event.AbortProcessingException;
-import javax.faces.event.ActionEvent;
 import javax.faces.event.FacesEvent;
-import javax.faces.event.PhaseId;
 import javax.faces.event.ValueChangeEvent;
 
 import org.ajax4jsf.component.AjaxComponent;
 import org.ajax4jsf.context.AjaxContext;
 import org.ajax4jsf.event.AjaxEvent;
-import org.ajax4jsf.event.AjaxSingleEvent;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.richfaces.event.CurrentDateChangeEvent;
@@ -162,6 +160,7 @@
 
 	public abstract void setHorizontalOffset(int horizontalOffset);
 
+
 	// TODO onclick add users onclick
 
 	// currentDate processing -------------------------------------------------
@@ -222,16 +221,51 @@
 	}
 
 	public Date getCurrentDateOrDefault() {
+
 		Date date = getCurrentDate();
+
 		if (date != null) {
 			return date;
 		} else {
-			Calendar calendar = getCalendar();
-			calendar.set(Calendar.DATE, 1);
-			return calendar.getTime();
+			Date value = getAsDate(this.getValue());
+			if (value != null) {
+				return value;
+			} else {
+				return java.util.Calendar.getInstance(getTimeZone()).getTime();
+			}
+
 		}
 	}
 
+	public Date getAsDate(Object date) {
+
+		if (date == null) {
+			return null;
+		} else {
+			if (date instanceof Date) {
+				return (Date) date;
+			} else {
+				if (date instanceof String) {
+					DateTimeConverter converter = new DateTimeConverter();
+					converter.setPattern(this.getDatePattern());
+					converter.setLocale(this.getLocale());
+					converter.setTimeZone(this.getTimeZone());
+					FacesContext context = FacesContext.getCurrentInstance();
+					return (Date) converter.getAsObject(context, this,
+							(String) date);
+				} else {
+					if (date instanceof Calendar) {
+						return ((Calendar) date).getTime();
+					} else {
+
+						throw new FacesException("Wrong attibute type");
+					}
+				}
+			}
+		}
+
+	}
+
 	public Object getTooltip(Date date) {
 
 		CalendarDataModel calendarDM = (CalendarDataModel) getDataModel();
@@ -455,5 +489,4 @@
 		removeFacesListener(listener);
 	}
 
-
 }




More information about the richfaces-svn-commits mailing list