Updated Branches: refs/heads/master 9553fc1aa -> 67734067d
WICKET-4998 + WICKET-4990 test that auto-complete event handler comes before any other event handler Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/67734067 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/67734067 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/67734067 Branch: refs/heads/master Commit: 67734067d563217f4a118f8d4a2712be954d3e97 Parents: 9553fc1 Author: svenmeier <svenme...@apache.org> Authored: Tue Feb 19 18:01:14 2013 +0100 Committer: svenmeier <svenme...@apache.org> Committed: Tue Feb 19 18:01:14 2013 +0100 ---------------------------------------------------------------------- .../examples/ajax/builtin/AutoCompletePage.java | 9 ++ .../markup/html/autocomplete/AutoCompletePage.html | 23 +++++ .../markup/html/autocomplete/AutoCompletePage.java | 73 +++++++++++++++ .../markup/html/autocomplete/AutoCompleteTest.java | 58 ++++++++++++ 4 files changed, 163 insertions(+), 0 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/67734067/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/AutoCompletePage.java ---------------------------------------------------------------------- diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/AutoCompletePage.java b/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/AutoCompletePage.java index cbeab07..a2749c4 100644 --- a/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/AutoCompletePage.java +++ b/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/AutoCompletePage.java @@ -22,6 +22,7 @@ import java.util.Iterator; import java.util.List; import java.util.Locale; +import org.apache.wicket.ajax.AjaxEventBehavior; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.form.AjaxFormSubmitBehavior; import org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField; @@ -83,6 +84,14 @@ public class AutoCompletePage extends BasePage final Label label = new Label("selectedValue", field.getDefaultModel()); label.setOutputMarkupId(true); + label.add(new AjaxEventBehavior("click") + { + @Override + protected void onEvent(AjaxRequestTarget target) + { + target.add(field); + } + }); form.add(label); field.add(new AjaxFormSubmitBehavior(form, "change") http://git-wip-us.apache.org/repos/asf/wicket/blob/67734067/wicket-extensions/src/test/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompletePage.html ---------------------------------------------------------------------- diff --git a/wicket-extensions/src/test/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompletePage.html b/wicket-extensions/src/test/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompletePage.html new file mode 100644 index 0000000..28b0b65 --- /dev/null +++ b/wicket-extensions/src/test/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompletePage.html @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- + 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. +--> +<html> +<body> + <input type="text" wicket:id="textfield" /> + <a wicket:id="link">link</a> +</body> +</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/wicket/blob/67734067/wicket-extensions/src/test/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompletePage.java ---------------------------------------------------------------------- diff --git a/wicket-extensions/src/test/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompletePage.java b/wicket-extensions/src/test/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompletePage.java new file mode 100644 index 0000000..a3696d0 --- /dev/null +++ b/wicket-extensions/src/test/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompletePage.java @@ -0,0 +1,73 @@ +/* + * 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.extensions.ajax.markup.html.autocomplete; + +import java.util.Arrays; +import java.util.Iterator; + +import org.apache.wicket.ajax.AjaxEventBehavior; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.markup.html.AjaxLink; +import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.model.Model; + +/** + * @author svenmeier + */ +public class AutoCompletePage extends WebPage +{ + private static final long serialVersionUID = 1L; + private AutoCompleteTextField<String> textField; + + /** + * Construct. + */ + public AutoCompletePage() + { + textField = new AutoCompleteTextField<String>("textfield", Model.of("")) + { + private static final long serialVersionUID = 1L; + + @Override + protected Iterator<String> getChoices(String input) + { + return Arrays.<String> asList().iterator(); + } + }; + textField.add(new AjaxEventBehavior("change") + { + private static final long serialVersionUID = 1L; + + @Override + protected void onEvent(AjaxRequestTarget target) + { + } + }); + add(textField); + + add(new AjaxLink<Void>("link") + { + private static final long serialVersionUID = 1L; + + @Override + public void onClick(AjaxRequestTarget target) + { + target.add(textField); + } + }); + } +} http://git-wip-us.apache.org/repos/asf/wicket/blob/67734067/wicket-extensions/src/test/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteTest.java ---------------------------------------------------------------------- diff --git a/wicket-extensions/src/test/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteTest.java b/wicket-extensions/src/test/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteTest.java new file mode 100644 index 0000000..93dedef --- /dev/null +++ b/wicket-extensions/src/test/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteTest.java @@ -0,0 +1,58 @@ +/* + * 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.extensions.ajax.markup.html.autocomplete; + +import org.apache.wicket.WicketTestCase; +import org.junit.Test; + +/** + * Test for {@link AutoCompleteBehavior}. + */ +public class AutoCompleteTest extends WicketTestCase +{ + + /** + * WICKET-4998 + WICKET-4990 + */ + @Test + public void autoCompleteAjaxBeforeChangeAjax() + { + tester.startPage(new AutoCompletePage()); + + String lastResponseAsString = tester.getLastResponseAsString(); + + int autoCompleteEventHandler = lastResponseAsString.indexOf("new Wicket.AutoComplete"); + int eventHandler = lastResponseAsString.indexOf("Wicket.Ajax.ajax"); + + assertTrue(autoCompleteEventHandler != -1); + assertTrue(eventHandler != -1); + + // autocomplete setup comes before event handler + assertTrue(autoCompleteEventHandler < eventHandler); + + tester.clickLink("link"); + + int autoCompleteEventHandler2 = lastResponseAsString.indexOf("new Wicket.AutoComplete"); + int eventHandler2 = lastResponseAsString.indexOf("Wicket.Ajax.ajax"); + + assertTrue(autoCompleteEventHandler2 != -1); + assertTrue(eventHandler2 != -1); + + // autocomplete setup comes before event handler + assertTrue(autoCompleteEventHandler2 < eventHandler2); + } +}