You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jd...@apache.org on 2009/01/19 08:46:46 UTC

svn commit: r735623 - in /wicket/trunk/wicket/src: main/java/org/apache/wicket/markup/html/form/ test/java/org/apache/wicket/markup/html/form/border/

Author: jdonnerstag
Date: Sun Jan 18 23:46:46 2009
New Revision: 735623

URL: http://svn.apache.org/viewvc?rev=735623&view=rev
Log:
fixed wicket-2027: FormComponentPanel does not work correctly inside a Border

Added:
    wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/
    wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/HomePage.html
    wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/HomePage.java
    wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/MyBorder.html
    wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/MyBorder.java
    wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/MyDateField.html
    wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/MyDateField.java
    wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/MyTextField.java
    wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/TestHomePage.java
Modified:
    wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java?rev=735623&r1=735622&r2=735623&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java Sun Jan 18 23:46:46 2009
@@ -1157,7 +1157,10 @@
 	{
 		FormComponent.visitFormComponentsPostOrder(this, visitor);
 
-		visitChildrenInContainingBorder(visitor);
+		if (getParent() instanceof Border)
+		{
+			FormComponent.visitFormComponentsPostOrder(getParent(), visitor);
+		}
 	}
 
 	/**
@@ -1969,16 +1972,7 @@
 		MarkupContainer border = findParent(Border.class);
 		if (border != null)
 		{
-			Iterator<? extends Component> iter = border.iterator();
-			Component.IVisitor<Component> visitor = new FormModelUpdateVisitor(null);
-			while (iter.hasNext())
-			{
-				Component child = iter.next();
-				if (child instanceof IFormModelUpdateListener)
-				{
-					visitor.component(child);
-				}
-			}
+			FormComponent.visitComponentsPostOrder(border, new FormModelUpdateVisitor(null));
 		}
 	}
 

Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/HomePage.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/HomePage.html?rev=735623&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/HomePage.html (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/HomePage.html Sun Jan 18 23:46:46 2009
@@ -0,0 +1,17 @@
+<html>
+    <head>
+        <title>Wicket Quickstart Archetype Homepage</title>
+    </head>
+    <body>
+        <strong>Wicket Quickstart Archetype Homepage</strong>
+        <br/><br/>
+        <span wicket:id="message">message will be here</span>
+
+		<div wicket:id="border">
+			teste<br />
+			<input wicket:id="textfield" /> - <span wicket:id="lbltextfield" /><br />
+			<input wicket:id="datefield" /> - <span wicket:id="lbldatefield" /><br />
+            <span wicket:id="datefield2"></span> - <span wicket:id="lbldatefield2" /><br />
+		</div>
+    </body>
+</html>

Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/HomePage.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/HomePage.java?rev=735623&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/HomePage.java (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/HomePage.java Sun Jan 18 23:46:46 2009
@@ -0,0 +1,88 @@
+/*
+ * 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
+ *
+ * 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.
+ */
+package org.apache.wicket.markup.html.form.border;
+
+import org.apache.wicket.PageParameters;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.model.PropertyModel;
+
+/**
+ * Homepage
+ */
+public class HomePage extends WebPage
+{
+	private static final long serialVersionUID = 1L;
+
+	private String textfield;
+	private String datefield;
+	private String datefield2;
+
+	public String getTextfield()
+	{
+		return textfield;
+	}
+
+	public void setTextfield(String textfield)
+	{
+		this.textfield = textfield;
+	}
+
+	public String getDatefield()
+	{
+		return datefield;
+	}
+
+	public void setDatefield(String datefield)
+	{
+		this.datefield = datefield;
+	}
+
+	public String getDatefield2()
+	{
+		return datefield2;
+	}
+
+	public void setDatefield2(String datefield)
+	{
+		datefield2 = datefield;
+	}
+
+	/**
+	 * Constructor that is invoked when page is invoked without a session.
+	 * 
+	 * @param parameters
+	 *            Page parameters
+	 */
+	public HomePage(final PageParameters parameters)
+	{
+		// Add the simplest type of label
+		add(new Label("message",
+			"If you see this message wicket is properly configured and running"));
+
+		MyBorder border = new MyBorder("border");
+		add(border);
+
+		border.add(new TextField<String>("textfield", new PropertyModel<String>(this, "textfield")));
+		border.add(new Label("lbltextfield", new PropertyModel<String>(this, "textfield")));
+		border.add(new MyTextField("datefield", new PropertyModel<String>(this, "datefield")).setOutputMarkupId(true));
+		border.add(new Label("lbldatefield", new PropertyModel<String>(this, "datefield")));
+		border.add(new MyDateField("datefield2", new PropertyModel<String>(this, "datefield2")).setOutputMarkupId(true));
+		border.add(new Label("lbldatefield2", new PropertyModel<String>(this, "datefield2")));
+	}
+}

Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/MyBorder.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/MyBorder.html?rev=735623&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/MyBorder.html (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/MyBorder.html Sun Jan 18 23:46:46 2009
@@ -0,0 +1,18 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
+	xmlns="http://www.w3.org/1999/xhtml"
+	xmlns:wicket="http://wicket.apache.org/"
+>
+<head>
+</head>
+<body>
+<wicket:border>
+
+<form wicket:id="form">
+	<wicket:body />
+	<button wicket:id="submit" type="submit">submit</button>
+</form>
+
+</wicket:border>
+</body>
+</html>

Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/MyBorder.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/MyBorder.java?rev=735623&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/MyBorder.java (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/MyBorder.java Sun Jan 18 23:46:46 2009
@@ -0,0 +1,48 @@
+/*
+ * 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
+ *
+ * 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.
+ */
+package org.apache.wicket.markup.html.form.border;
+
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
+import org.apache.wicket.markup.html.border.Border;
+import org.apache.wicket.markup.html.form.Form;
+
+
+public class MyBorder extends Border
+{
+	private static final long serialVersionUID = 1L;
+
+	public MyBorder(String id)
+	{
+		super(id);
+
+		final Form<Void> form = new Form<Void>("form");
+		form.setOutputMarkupId(true);
+		add(form);
+
+		form.add(new AjaxSubmitLink("submit")
+		{
+			private static final long serialVersionUID = 1L;
+
+			@Override
+			protected void onSubmit(AjaxRequestTarget target, Form<?> form)
+			{
+				target.addComponent(form);
+			}
+		});
+	}
+}

Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/MyDateField.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/MyDateField.html?rev=735623&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/MyDateField.html (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/MyDateField.html Sun Jan 18 23:46:46 2009
@@ -0,0 +1,21 @@
+<!--
+   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
+
+   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.
+-->
+<wicket:panel>
+  <span style="white-space: nowrap;">
+    <input type="text" wicket:id="date" size="8" />
+  </span>
+</wicket:panel>
\ No newline at end of file

Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/MyDateField.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/MyDateField.java?rev=735623&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/MyDateField.java (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/MyDateField.java Sun Jan 18 23:46:46 2009
@@ -0,0 +1,122 @@
+/*
+ * 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
+ *
+ * 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.
+ */
+package org.apache.wicket.markup.html.form.border;
+
+import org.apache.wicket.markup.html.form.FormComponentPanel;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.PropertyModel;
+
+/**
+ * This is not a real DateField. It only servers some testing purposes (derived from
+ * FormComponentPanel)
+ */
+public class MyDateField extends FormComponentPanel<String>
+{
+	private static final long serialVersionUID = 1L;
+
+	private String date;
+
+	private final TextField<String> dateField;
+
+	/**
+	 * Construct.
+	 * 
+	 * @param id
+	 */
+	public MyDateField(String id)
+	{
+		this(id, null);
+	}
+
+	/**
+	 * Construct.
+	 * 
+	 * @param id
+	 * @param model
+	 */
+	public MyDateField(String id, IModel<String> model)
+	{
+		super(id, model);
+		setType(String.class);
+		PropertyModel<String> dateFieldModel = new PropertyModel<String>(this, "date");
+		add(dateField = new TextField<String>("date", dateFieldModel));
+	}
+
+	/**
+	 * Gets date.
+	 * 
+	 * @return date
+	 */
+	public String getDate()
+	{
+		return date;
+	}
+
+	/**
+	 * Sets date.
+	 * 
+	 * @param date
+	 *            date
+	 */
+	public void setDate(String date)
+	{
+		this.date = date;
+		setDefaultModelObject(date);
+	}
+
+	/**
+	 * Sets 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>
+	 * 
+	 * @see org.apache.wicket.markup.html.form.FormComponent#convertInput()
+	 */
+	@Override
+	protected void convertInput()
+	{
+		setConvertedInput(dateField.getConvertedInput() + "-converted");
+	}
+
+	/**
+	 * @see org.apache.wicket.Component#onBeforeRender()
+	 */
+	@Override
+	protected void onBeforeRender()
+	{
+		dateField.setRequired(isRequired());
+
+		String d = (String)getDefaultModelObject();
+		if (d != null)
+		{
+			date = d;
+		}
+		else
+		{
+			date = null;
+		}
+
+		super.onBeforeRender();
+	}
+}

Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/MyTextField.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/MyTextField.java?rev=735623&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/MyTextField.java (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/MyTextField.java Sun Jan 18 23:46:46 2009
@@ -0,0 +1,60 @@
+/*
+ * 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
+ *
+ * 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.
+ */
+package org.apache.wicket.markup.html.form.border;
+
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.model.IModel;
+
+/**
+ * 
+ */
+public class MyTextField extends TextField<String>
+{
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * Construct.
+	 * 
+	 * @param id
+	 */
+	public MyTextField(String id)
+	{
+		this(id, null);
+	}
+
+	/**
+	 * Construct.
+	 * 
+	 * @param id
+	 * @param model
+	 */
+	public MyTextField(String id, IModel<String> model)
+	{
+		super(id, model);
+		setType(String.class);
+	}
+
+	/**
+	 * 
+	 * @see org.apache.wicket.markup.html.form.FormComponent#convertInput()
+	 */
+	@Override
+	protected void convertInput()
+	{
+		super.setConvertedInput(getInput() + "-converted");
+	}
+}

Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/TestHomePage.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/TestHomePage.java?rev=735623&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/TestHomePage.java (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/border/TestHomePage.java Sun Jan 18 23:46:46 2009
@@ -0,0 +1,77 @@
+/*
+ * 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
+ *
+ * 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.
+ */
+package org.apache.wicket.markup.html.form.border;
+
+import junit.framework.TestCase;
+
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.util.tester.FormTester;
+import org.apache.wicket.util.tester.WicketTester;
+
+/**
+ * Simple test using the WicketTester
+ */
+public class TestHomePage extends TestCase
+{
+	private WicketTester tester;
+
+	private FormTester formTester;
+
+	@Override
+	public void setUp()
+	{
+		tester = new WicketTester();
+
+		// Start and render the test page
+		tester.startPage(HomePage.class);
+		tester.assertRenderedPage(HomePage.class);
+	}
+
+	/**
+	 * 
+	 */
+	public void testWithBorder2()
+	{
+		formTester = tester.newFormTester("border:form");
+
+		// formTester.setValue("..:textfield1", "testxxx");
+		TextField<String> textfield = (TextField<String>)tester.getLastRenderedPage().get(
+			"border:textfield");
+		tester.getServletRequest().setParameter(textfield.getInputName(), "abcde");
+
+		MyTextField datefield = (MyTextField)tester.getLastRenderedPage().get("border:datefield");
+		tester.getServletRequest().setParameter(datefield.getInputName(), "aaabbb");
+
+		MyDateField datefield2 = (MyDateField)tester.getLastRenderedPage().get("border:datefield2");
+		TextField<String> date = (TextField<String>)datefield2.get("date");
+		tester.getServletRequest().setParameter(date.getInputName(), "abcdef");
+
+		formTester.submit();
+		tester.assertNoErrorMessage();
+
+		HomePage page = (HomePage)tester.getLastRenderedPage();
+		assertEquals("abcde", page.getTextfield());
+		assertEquals("aaabbb-converted", page.getDatefield());
+		assertEquals("abcdef-converted", page.getDatefield2());
+
+		assertEquals("abcde", page.get("border:lbltextfield").getDefaultModelObjectAsString());
+		assertEquals("aaabbb-converted", page.get("border:lbldatefield")
+			.getDefaultModelObjectAsString());
+		assertEquals("abcdef-converted", page.get("border:lbldatefield2")
+			.getDefaultModelObjectAsString());
+	}
+}