Repository: wicket
Updated Branches:
  refs/heads/master 9c552ff7c -> 8fbe6c7d5


Re-introduced onDetach to fix WICKET-5960

This might be a temporary fix for WICKET-5960, because it is odd that
HtmlHeaderContainer.onAfterRender is not called during an AJAX render.

Adding onDetach fixes the bug introduced by renaming it to onAfterRender.


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/8fbe6c7d
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/8fbe6c7d
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/8fbe6c7d

Branch: refs/heads/master
Commit: 8fbe6c7d5810debbab10395893a31aea7423aaad
Parents: 9c552ff
Author: Martijn Dashorst <[email protected]>
Authored: Thu Aug 13 17:18:56 2015 +0200
Committer: Martijn Dashorst <[email protected]>
Committed: Thu Aug 13 17:19:23 2015 +0200

----------------------------------------------------------------------
 .../html/internal/HtmlHeaderContainer.java      |  8 ++
 .../wicket/request/cycle/RerenderAjaxPage.html  | 20 +++++
 .../wicket/request/cycle/RerenderAjaxPage.java  | 83 ++++++++++++++++++++
 3 files changed, 111 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/8fbe6c7d/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/HtmlHeaderContainer.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/HtmlHeaderContainer.java
 
b/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/HtmlHeaderContainer.java
index e906560..73aa021 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/HtmlHeaderContainer.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/HtmlHeaderContainer.java
@@ -321,6 +321,14 @@ public class HtmlHeaderContainer extends 
TransparentWebMarkupContainer
                headerResponse = null;
        }
 
+       @Override
+       protected void onDetach() {
+               super.onDetach();
+
+               renderedComponentsPerScope = null;
+               headerResponse = null;
+       }
+
        /**
         * Factory method for creating header response
         * 

http://git-wip-us.apache.org/repos/asf/wicket/blob/8fbe6c7d/wicket-core/src/test/java/org/apache/wicket/request/cycle/RerenderAjaxPage.html
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/test/java/org/apache/wicket/request/cycle/RerenderAjaxPage.html
 
b/wicket-core/src/test/java/org/apache/wicket/request/cycle/RerenderAjaxPage.html
new file mode 100644
index 0000000..66cb483
--- /dev/null
+++ 
b/wicket-core/src/test/java/org/apache/wicket/request/cycle/RerenderAjaxPage.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html xmlns:wicket="http://wicket.apache.org";>
+       <head>
+               <meta charset="utf-8" />
+               <title>Wicket 5960</title>
+       </head>
+       <body>
+               <h1>Wicket 5960</h1>
+               <div id="invisible" style="background-color:red;margin:25px 
auto;padding:50px;text-align:center;color:white;width:66%;max-width:66%;font-size:48pt;font-family:'Comic
 Sans MS'">
+                       It broke. Now you see this message.
+               </div>
+               <div wicket:id="feedback"></div>
+               <form wicket:id="form">
+               <fieldset>
+                       <input type="text" placeholder="Username" 
wicket:id="username">
+                       <input type="submit" value="Login">
+               </fieldset>
+               </form>
+       </body>
+</html>

http://git-wip-us.apache.org/repos/asf/wicket/blob/8fbe6c7d/wicket-core/src/test/java/org/apache/wicket/request/cycle/RerenderAjaxPage.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/test/java/org/apache/wicket/request/cycle/RerenderAjaxPage.java
 
b/wicket-core/src/test/java/org/apache/wicket/request/cycle/RerenderAjaxPage.java
new file mode 100644
index 0000000..4eb4439
--- /dev/null
+++ 
b/wicket-core/src/test/java/org/apache/wicket/request/cycle/RerenderAjaxPage.java
@@ -0,0 +1,83 @@
+/*
+ * 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.request.cycle;
+
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.form.AjaxFormValidatingBehavior;
+import org.apache.wicket.markup.head.CssContentHeaderItem;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.markup.html.panel.FeedbackPanel;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+import org.apache.wicket.validation.validator.StringValidator;
+
+@SuppressWarnings("javadoc")
+public class RerenderAjaxPage extends WebPage
+{
+       private static final long serialVersionUID = 1L;
+
+       public static final String HEAD_TEXT = "#invisible { display:none; 
}\nbody {background-color:#ccc; }\n";
+
+       private FeedbackPanel feedback;
+
+       public RerenderAjaxPage(final PageParameters parameters)
+       {
+               super(parameters);
+
+               // the page needs a component that is refreshed using AJAX, so 
a feedback panel will do
+               // nicely
+               feedback = new FeedbackPanel("feedback");
+               add(feedback.setOutputMarkupPlaceholderTag(true));
+
+               Form<Void> form = new Form<Void>("form");
+               add(form);
+               TextField<String> username = new TextField<String>("username", 
Model.of(""));
+
+               // make it so we can never ever have a successful submit
+               username.add(StringValidator.minimumLength(Integer.MAX_VALUE));
+               form.add(username.setRequired(true));
+
+               // add an AJAX event to the text field so we can trigger the 
WICKET-5960 AJAX render bug
+               username.add(new AjaxFormValidatingBehavior("blur")
+               {
+                       private static final long serialVersionUID = 1L;
+
+                       @Override
+                       protected void onError(AjaxRequestTarget target)
+                       {
+                               super.onError(target);
+
+                               // add the component to the AJAX envelope so 
that we trigger a
+                               // PartialHtmlHeaderContainer to be set on the 
page.
+                               target.add(feedback);
+                       }
+               });
+       }
+
+       @Override
+       public void renderHead(IHeaderResponse response)
+       {
+               super.renderHead(response);
+
+               // and add our own special sauce to the page to emphasize the 
issue. If this CSS is not
+               // rendered, the page will show a big red box telling you about 
the failure.
+               response.render(new CssContentHeaderItem(HEAD_TEXT, "mystyle", 
null));
+       }
+}

Reply via email to