You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by eh...@apache.org on 2007/06/05 20:56:08 UTC

svn commit: r544593 - in /incubator/wicket/trunk/jdk-1.4: wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/ wicket/src/main/java/org/apache/wicket/markup/html/form/

Author: ehillenius
Date: Tue Jun  5 11:56:07 2007
New Revision: 544593

URL: http://svn.apache.org/viewvc?view=rev&rev=544593
Log:
WICKET-500

Modified:
    incubator/wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateField.java
    incubator/wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.java
    incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java

Modified: incubator/wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateField.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateField.java?view=diff&rev=544593&r1=544592&r2=544593
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateField.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateField.java Tue Jun  5 11:56:07 2007
@@ -24,7 +24,6 @@
 import org.apache.wicket.model.PropertyModel;
 import org.joda.time.MutableDateTime;
 
-
 /**
  * Works on a {@link java.util.Date} object. Displays a date field and a
  * {@link CalendarPopup calendar popup}.
@@ -33,7 +32,6 @@
  */
 public class DateField extends FormComponentPanel
 {
-
 	private static final long serialVersionUID = 1L;
 
 	private MutableDateTime date;
@@ -64,6 +62,28 @@
 	}
 
 	/**
+	 * Gets the converted input. In this case, we're really just interested in
+	 * the nested date field, as that is the element that receives the real user
+	 * input. So we're just passing that on.
+	 * <p>
+	 * Note that overriding this method is a better option than overriding
+	 * {@link #updateModel()} like the first versions of this class did. The
+	 * reason for that is that this method can be used by form validators
+	 * without having to depend on the actual model being updated, and this
+	 * method is called by the default implementation of {@link #updateModel()}
+	 * anyway (so we don't have to override that anymore).
+	 * </p>
+	 * 
+	 * @return instance of {@link Date}, possibly null
+	 * 
+	 * @see org.apache.wicket.markup.html.form.FormComponent#getConvertedInput()
+	 */
+	public Object getConvertedInput()
+	{
+		return dateField.getConvertedInput();
+	}
+
+	/**
 	 * Gets date.
 	 * 
 	 * @return date
@@ -82,23 +102,7 @@
 	public void setDate(Date date)
 	{
 		this.date = (date != null) ? new MutableDateTime(date) : null;
-	}
-
-	/**
-	 * @see org.apache.wicket.markup.html.form.FormComponent#updateModel()
-	 */
-	public void updateModel()
-	{
-
-		if (date != null)
-		{
-			Date d = date.toDate();
-			setModelObject(d);
-		}
-		else
-		{
-			setModelObject(null);
-		}
+		setModelObject(date);
 	}
 
 	/**
@@ -106,7 +110,6 @@
 	 */
 	private void init()
 	{
-
 		setType(Date.class);
 		add(dateField = DateTextField.forShortStyle("date", new PropertyModel(this, "date")));
 		dateField.add(new DatePicker());
@@ -117,7 +120,6 @@
 	 */
 	protected void onBeforeRender()
 	{
-
 		Date d = (Date)getModelObject();
 		if (d != null)
 		{

Modified: incubator/wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.java?view=diff&rev=544593&r1=544592&r2=544593
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.java Tue Jun  5 11:56:07 2007
@@ -48,7 +48,6 @@
 // systems with AM/PM, others have 24 hour systems
 public class DateTimeField extends FormComponentPanel
 {
-
 	/**
 	 * Enumerated type for different ways of handling the render part of
 	 * requests.
@@ -56,7 +55,6 @@
 	// enums are mucho nicer, but let's keep this project at 1.4 for now
 	private static class AM_PM extends EnumeratedType
 	{
-
 		private static final long serialVersionUID = 1L;
 
 		static final AM_PM AM = new AM_PM("AM");
@@ -126,6 +124,67 @@
 	}
 
 	/**
+	 * Gets the converted input. It combines the inputs of the nested date,
+	 * hours, minutes and am/pm fields and constructs a date from it.
+	 * <p>
+	 * Note that overriding this method is a better option than overriding
+	 * {@link #updateModel()} like the first versions of this class did. The
+	 * reason for that is that this method can be used by form validators
+	 * without having to depend on the actual model being updated, and this
+	 * method is called by the default implementation of {@link #updateModel()}
+	 * anyway (so we don't have to override that anymore).
+	 * </p>
+	 * 
+	 * @return instance of {@link Date}, possibly null
+	 * 
+	 * @see org.apache.wicket.markup.html.form.FormComponent#getConvertedInput()
+	 */
+	public Object getConvertedInput()
+	{
+		MutableDateTime date = new MutableDateTime(dateField.getConvertedInput());
+		Integer hours = (Integer)hoursField.getConvertedInput();
+		Integer minutes = (Integer)minutesField.getConvertedInput();
+		AM_PM amOrPm = (AM_PM)amOrPmChoice.getConvertedInput();
+
+		if (date != null)
+		{
+			try
+			{
+				TimeZone zone = getClientTimeZone();
+				if (zone != null)
+				{
+					date.setZone(DateTimeZone.forTimeZone(zone));
+				}
+
+				if (hours != null)
+				{
+					date.set(DateTimeFieldType.hourOfHalfday(), hours.intValue() % 12);
+					date.setMinuteOfHour((minutes != null) ? minutes.intValue() : 0);
+				}
+				if (amOrPm == AM_PM.PM)
+				{
+					date.set(DateTimeFieldType.halfdayOfDay(), 1);
+				}
+				else
+				{
+					date.set(DateTimeFieldType.halfdayOfDay(), 0);
+				}
+
+				// the date will be in the server's timezone
+				return date.toDate();
+			}
+			catch (RuntimeException e)
+			{
+				DateTimeField.this.error(e.getMessage());
+				invalid();
+			}
+
+		}
+
+		return null;
+	}
+
+	/**
 	 * Gets date.
 	 * 
 	 * @return date
@@ -175,6 +234,7 @@
 	public void setDate(Date date)
 	{
 		this.date = (date != null) ? new MutableDateTime(date) : null;
+		setModelObject(date);
 	}
 
 	/**
@@ -200,53 +260,6 @@
 	}
 
 	/**
-	 * @see org.apache.wicket.markup.html.form.FormComponent#updateModel()
-	 */
-	public void updateModel()
-	{
-		if (date != null)
-		{
-			try
-			{
-				TimeZone zone = getClientTimeZone();
-				if (zone != null)
-				{
-					date.setZone(DateTimeZone.forTimeZone(zone));
-				}
-
-				if (hours != null)
-				{
-					date.set(DateTimeFieldType.hourOfHalfday(), hours.intValue() % 12);
-					date.setMinuteOfHour((minutes != null) ? minutes.intValue() : 0);
-				}
-				if (amOrPm == AM_PM.PM)
-				{
-					date.set(DateTimeFieldType.halfdayOfDay(), 1);
-				}
-				else
-				{
-					date.set(DateTimeFieldType.halfdayOfDay(), 0);
-				}
-
-				// the date will be in the server's timezone
-				Date d = date.toDate();
-				setModelObject(d);
-
-			}
-			catch (RuntimeException e)
-			{
-				DateTimeField.this.error(e.getMessage());
-				invalid();
-			}
-
-		}
-		else
-		{
-			setModelObject(null);
-		}
-	}
-
-	/**
 	 * Gets the client's time zone.
 	 * 
 	 * @return The client's time zone or null
@@ -263,7 +276,6 @@
 
 	private void init()
 	{
-
 		setType(Date.class);
 		add(dateField = DateTextField.forShortStyle("date", new PropertyModel(this, "date")));
 		dateField.add(new DatePicker());
@@ -283,7 +295,6 @@
 	 */
 	protected void onBeforeRender()
 	{
-
 		Date d = (Date)getModelObject();
 		if (d != null)
 		{

Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java?view=diff&rev=544593&r1=544592&r2=544593
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java Tue Jun  5 11:56:07 2007
@@ -548,9 +548,14 @@
 	}
 
 	/**
+	 * Gets the converter input. You typically should not override this method,
+	 * unless you are writing a
+	 * {@link FormComponentPanel special form component} that embeds other form
+	 * components that receive the real user input.
+	 * 
 	 * @return value of input converted into appropriate type if any was set
 	 */
-	public final Object getConvertedInput()
+	public Object getConvertedInput()
 	{
 		return convertedInput;
 	}
@@ -833,8 +838,10 @@
 	 */
 	public final boolean isValid()
 	{
-		class IsValidVisitor implements IVisitor {
+		class IsValidVisitor implements IVisitor
+		{
 			boolean valid = true;
+
 			public Object formComponent(IFormVisitorParticipant formComponent)
 			{
 				final FormComponent fc = (FormComponent)formComponent;