Author: jdonnerstag
Date: Mon Jun 1 17:49:47 2009
New Revision: 780750
URL: http://svn.apache.org/viewvc?rev=780750&view=rev
Log:
fixed WicketTester.executeAjaxEvent(AjaxButton, "onclick"); results in clicking
of another submit button if its model value is not null.
Issue: WICKET-2274
Added:
wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/form/
wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/form/AjaxButtonTest.java
wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/form/HomePage.html
wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/form/HomePage.java
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java?rev=780750&r1=780749&r2=780750&view=diff
==============================================================================
---
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
(original)
+++
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
Mon Jun 1 17:49:47 2009
@@ -748,7 +748,7 @@
WebRequestCycle requestCycle =
setupRequestAndResponse(true);
- submitAjaxFormSubmitBehavior(ajaxFormSubmitBehavior);
+ submitAjaxFormSubmitBehavior(linkComponent,
ajaxFormSubmitBehavior);
// Ok, finally we "click" the link
ajaxFormSubmitBehavior.onRequest();
@@ -1188,7 +1188,7 @@
if (ajaxEventBehavior instanceof AjaxFormSubmitBehavior)
{
AjaxFormSubmitBehavior ajaxFormSubmitBehavior =
(AjaxFormSubmitBehavior)ajaxEventBehavior;
- submitAjaxFormSubmitBehavior(ajaxFormSubmitBehavior);
+ submitAjaxFormSubmitBehavior(component,
ajaxFormSubmitBehavior);
}
// process the event
@@ -1270,10 +1270,13 @@
* Helper method for all the places where an Ajax call should submit an
associated
* <code>Form</code>.
*
+ * @param component
+ * The component the behavior is attached to
* @param behavior
* The <code>AjaxFormSubmitBehavior</code> with the
<code>Form</code> to "submit"
*/
- private void submitAjaxFormSubmitBehavior(AjaxFormSubmitBehavior
behavior)
+ private void submitAjaxFormSubmitBehavior(final Component component,
+ AjaxFormSubmitBehavior behavior)
{
// We need to get the form submitted, using reflection.
// It needs to be "submitted".
@@ -1297,17 +1300,20 @@
@Override
public void onFormComponent(FormComponent<?>
formComponent)
{
- if (formComponent.isVisible())
+ if (!(formComponent instanceof RadioGroup) &&
+ !(formComponent instanceof CheckGroup)
&&
+
!formComponent.getClass().isAssignableFrom(Button.class) &&
+ formComponent.isVisible())
{
- if (!(formComponent instanceof
RadioGroup) &&
- !(formComponent instanceof
CheckGroup) &&
-
!(formComponent.getClass().isAssignableFrom(Button.class)))
+ if (!((formComponent instanceof Button)
&& (component instanceof Button)) ||
+ (component == formComponent))
{
String name =
formComponent.getInputName();
String value =
formComponent.getValue();
- // Set request parameter with
the field value, but do not modify an existing
- // request parameter explicitly
set using FormTester.setValue()
+ // Set request parameter with
the field value, but do not modify an
+ // existing request parameter
explicitly set using
+ // FormTester.setValue()
if
(getServletRequest().getParameterMap().get(name) == null)
{
getServletRequest().setParameter(name, value);
Added:
wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/form/AjaxButtonTest.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/form/AjaxButtonTest.java?rev=780750&view=auto
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/form/AjaxButtonTest.java
(added)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/form/AjaxButtonTest.java
Mon Jun 1 17:49:47 2009
@@ -0,0 +1,54 @@
+/*
+ * 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.ajax.markup.html.form;
+
+import junit.framework.TestCase;
+
+import org.apache.wicket.util.tester.WicketTester;
+
+/**
+ * Simple test using the WicketTester
+ */
+public class AjaxButtonTest extends TestCase
+{
+ private WicketTester tester;
+
+ @Override
+ public void setUp()
+ {
+ tester = new WicketTester();
+ }
+
+ /**
+ *
+ */
+ public void testAjaxButtonWhenCancelButtonHasAModelValue()
+ {
+ // start and render the test page
+ tester.startPage(HomePage.class);
+ // assert rendered page class
+ tester.assertRenderedPage(HomePage.class);
+ // assert rendered label component
+ tester.assertLabel("message",
+ "If you see this message wicket is properly configured
and running");
+
+ // assert rendered page class
+ HomePage homePage = (HomePage)tester.getLastRenderedPage();
+ TestForm testForm = homePage.getForm();
+ tester.executeAjaxEvent(testForm.getSubmitButton(), "onclick");
+ }
+}
\ No newline at end of file
Added:
wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/form/HomePage.html
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/form/HomePage.html?rev=780750&view=auto
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/form/HomePage.html
(added)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/form/HomePage.html
Mon Jun 1 17:49:47 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>
+
+ <form wicket:id="form">
+ <input type="submit" wicket:id="cancel" value="Submit"/>
+ <input type="submit" wicket:id="submit" value="Submit"/>
+ </form>
+
+ </body>
+</html>
+
Added:
wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/form/HomePage.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/form/HomePage.java?rev=780750&view=auto
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/form/HomePage.java
(added)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/form/HomePage.java
Mon Jun 1 17:49:47 2009
@@ -0,0 +1,93 @@
+/*
+ * 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.ajax.markup.html.form;
+
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.form.Button;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.model.Model;
+
+/**
+ * Homepage
+ */
+public class HomePage extends WebPage
+{
+ private static final long serialVersionUID = 1L;
+ private final TestForm form;
+
+ /**
+ *
+ */
+ public HomePage()
+ {
+ add(new Label("message",
+ "If you see this message wicket is properly configured
and running"));
+ add(form = new TestForm("form"));
+ }
+
+ /**
+ * @return the form
+ */
+ public TestForm getForm()
+ {
+ return form;
+ }
+}
+
+class TestForm extends Form<Void>
+{
+ private static final long serialVersionUID = 1L;
+ private final Button submitButton;
+
+ public TestForm(String id)
+ {
+ super(id);
+ add((new Button("cancel", Model.of("I am not empty label"))
+ {
+ @Override
+ public void onSubmit()
+ {
+ throw new IllegalStateException("CANCEL button
hit!");
+ }
+ }).setDefaultFormProcessing(false));
+
+ add((submitButton = new AjaxButton("submit")
+ {
+ @Override
+ protected void onSubmit(AjaxRequestTarget target,
Form<?> form)
+ {
+ System.out.println("Ajax ok");
+ }
+ }).setDefaultFormProcessing(false));
+ }
+
+ @Override
+ protected void onSubmit()
+ {
+ throw new IllegalStateException("Submit not pressed via ajax!");
+ }
+
+ /**
+ * @return the submitButton
+ */
+ public Button getSubmitButton()
+ {
+ return submitButton;
+ }
+}