You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2007/01/04 03:42:15 UTC

svn commit: r492389 - /incubator/wicket/branches/wicket-1.x/wicket-extensions/src/main/java/wicket/extensions/markup/html/form/palette/component/Recorder.java

Author: ivaynberg
Date: Wed Jan  3 18:42:14 2007
New Revision: 492389

URL: http://svn.apache.org/viewvc?view=rev&rev=492389
Log:
bugfix for model sync issues

Modified:
    incubator/wicket/branches/wicket-1.x/wicket-extensions/src/main/java/wicket/extensions/markup/html/form/palette/component/Recorder.java

Modified: incubator/wicket/branches/wicket-1.x/wicket-extensions/src/main/java/wicket/extensions/markup/html/form/palette/component/Recorder.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket-extensions/src/main/java/wicket/extensions/markup/html/form/palette/component/Recorder.java?view=diff&rev=492389&r1=492388&r2=492389
==============================================================================
--- incubator/wicket/branches/wicket-1.x/wicket-extensions/src/main/java/wicket/extensions/markup/html/form/palette/component/Recorder.java (original)
+++ incubator/wicket/branches/wicket-1.x/wicket-extensions/src/main/java/wicket/extensions/markup/html/form/palette/component/Recorder.java Wed Jan  3 18:42:14 2007
@@ -1,18 +1,18 @@
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
  * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
  */
 package wicket.extensions.markup.html.form.palette.component;
 
@@ -38,8 +38,8 @@
 {
 	private static final long serialVersionUID = 1L;
 
-	private static final String[] EMPTY_IDS=new String[0];
-	
+	private static final String[] EMPTY_IDS = new String[0];
+
 	/** conviniently maintained array of selected ids */
 	private String[] ids;
 
@@ -66,13 +66,31 @@
 		this.palette = palette;
 
 		setOutputMarkupId(true);
-		
+		initIds();
+	}
+
+	protected void onAttach()
+	{
+		super.onAttach();
+
+		if (!getForm().hasError())
+		{
+			initIds();
+		}
+
+	}
+
+	/**
+	 * Syncrhonize ids collection from the palette's model
+	 */
+	private void initIds()
+	{
 		// construct the model string based on selection collection
 		IChoiceRenderer renderer = getPalette().getChoiceRenderer();
 		StringBuffer modelStringBuffer = new StringBuffer();
 		Iterator selection = getPalette().getModelCollection().iterator();
-		
-		int i=0;
+
+		int i = 0;
 		while (selection.hasNext())
 		{
 			modelStringBuffer.append(renderer.getIdValue(selection.next(), i++));
@@ -88,7 +106,7 @@
 		updateIds(modelString);
 	}
 
-	
+
 	protected void onValid()
 	{
 		super.onValid();
@@ -172,10 +190,14 @@
 		updateIds(getValue());
 	}
 
-	private void updateIds(String value) {
-		if (Strings.isEmpty(value)) {
-			ids=EMPTY_IDS;
-		} else {
+	private void updateIds(String value)
+	{
+		if (Strings.isEmpty(value))
+		{
+			ids = EMPTY_IDS;
+		}
+		else
+		{
 			ids = value.split(",");
 		}
 	}