Index: FormComponent.java
===================================================================
RCS file: /cvsroot/wicket/wicket/src/java/wicket/markup/html/form/FormComponent.java,v
retrieving revision 1.58
diff -u -r1.58 FormComponent.java
--- FormComponent.java	9 Nov 2005 22:29:04 -0000	1.58
+++ FormComponent.java	18 Nov 2005 00:48:45 -0000
@@ -106,25 +106,26 @@
 	protected static final short FLAG_CONVERT_EMPTY_INPUT_STRING_TO_NULL = FLAG_RESERVED1;
 
 	/**
-	 * Special flag value to indicate when there is no invalid input, since null
-	 * is a valid value!
-	 */
-	protected static final String NO_INVALID_INPUT = "[No invalid input]";
-
-	/**
 	 * Whether this form component should save and restore state between
 	 * sessions. This is false by default.
 	 */
 	private static final short FLAG_PERSISTENT = FLAG_RESERVED2;
 
 	/**
-	 * When the user input does not validate, this is a temporary store for the
-	 * input he/she provided. We have to store it somewhere as we loose the
-	 * request parameter when redirecting.
+	 * Raw Input entered by the user
 	 */
-	private String invalidInput = NO_INVALID_INPUT;
+	private String rawInput = null;
 
 	/**
+	 * Indicates if the model is considered up to date with the last user input.
+	 * If true, the model value will be used to render the component.
+	 * If false, the rawInput value (last user input) will be used to render the component.
+	 * (Can be false if validation fails, or if component not validated/updated after a user input,
+	 * for example if a Button with defaultFormProcessing property set to true, aka "immediate button")  
+	 */
+	private boolean modelUpToDate = true;
+	
+	/**
 	 * The list of validators for this form component as either an IValidator
 	 * instance or an array of IValidator instances.
 	 */
@@ -301,7 +302,14 @@
 	 */
 	public final String getValue()
 	{
-		return NO_INVALID_INPUT.equals(invalidInput) ? getModelValue() : invalidInput;
+		if (modelUpToDate)
+		{
+			return getModelValue();
+		}
+		else
+		{
+			return rawInput;
+		}
 	}
 
 	/**
@@ -512,24 +520,10 @@
 	}
 
 	/**
-	 * Handle invalidation by storing the user input for form repopulation
+	 * Handle invalidation
 	 */
 	protected void onInvalid()
 	{
-		// Get input as String array
-		final String[] input = inputAsStringArray();
-
-		// If there is any input
-		if (input != null)
-		{
-			// join the values together with ";", for example, "id1;id2;id3"
-			invalidInput = StringList.valueOf(input).join(";");
-		}
-		else
-		{
-			// no input
-			invalidInput = null;
-		}
 	}
 
 	/**
@@ -537,6 +531,8 @@
 	 */
 	protected void onModelChanged()
 	{
+		modelUpToDate = true;
+
 		// If the model for this form component changed, we should make it
 		// valid again because there can't be any invalid input for it anymore.
 		valid();
@@ -547,7 +543,6 @@
 	 */
 	protected void onValid()
 	{
-		invalidInput = NO_INVALID_INPUT;
 	}
 
 	/**
@@ -628,4 +623,40 @@
 		}
 		return 1;
 	}
+	
+	/**
+	 * Used by Form to tell the FormComponent that a new user input is available  
+	 */
+	final void registerNewUserInput() 
+	{
+		if (isVisibleInHierarchy()) 
+		{
+			rawInput = getUserInput();
+			modelUpToDate = false;
+		}
+	}
+	
+	/**
+	 * @return The value of the user input for this form component
+	 */
+	private String getUserInput() 
+	{
+		String rawInput;
+		// Get input as String array
+		final String[] input = inputAsStringArray();
+
+		// If there is any input
+		if (input != null)
+		{
+			// join the values together with ";", for example, "id1;id2;id3"
+			rawInput = StringList.valueOf(input).join(";");
+		}
+		else
+		{
+			// no input
+			rawInput = null;
+		}
+		return rawInput;
+	}
+	
 }

