Author: ivaynberg
Date: Fri Dec 29 16:54:00 2006
New Revision: 491143
URL: http://svn.apache.org/viewvc?view=rev&rev=491143
Log:
reworked how attaching/detaching components happens during ajax, WICKET-156,
WICKET-112
Modified:
incubator/wicket/trunk/wicket/src/main/java/wicket/Component.java
incubator/wicket/trunk/wicket/src/main/java/wicket/Page.java
incubator/wicket/trunk/wicket/src/main/java/wicket/ajax/AjaxRequestTarget.java
incubator/wicket/trunk/wicket/src/main/java/wicket/request/target/component/ComponentRequestTarget.java
Modified: incubator/wicket/trunk/wicket/src/main/java/wicket/Component.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/Component.java?view=diff&rev=491143&r1=491142&r2=491143
==============================================================================
--- incubator/wicket/trunk/wicket/src/main/java/wicket/Component.java (original)
+++ incubator/wicket/trunk/wicket/src/main/java/wicket/Component.java Fri Dec
29 16:54:00 2006
@@ -1847,32 +1847,6 @@
try
{
- if (this instanceof MarkupContainer)
- {
- MarkupContainer<T> container =
(MarkupContainer<T>)this;
-
- // First, give priority to IFeedback
instances, as they have
- // to collect their messages before
components like
- // ListViews remove any child components
-
container.visitChildren(IFeedback.class, new IVisitor()
- {
- public Object
component(Component component)
- {
-
((IFeedback)component).updateFeedback();
-
component.internalAttach();
- return
IVisitor.CONTINUE_TRAVERSAL;
- }
- });
- }
-
- if (this instanceof IFeedback)
- {
- ((IFeedback)this).updateFeedback();
- }
-
- // attach
- internalAttach();
-
// check authorization
// first the component itself
// (after attach as otherwise list views etc
wont work)
@@ -1903,9 +1877,6 @@
{
onAfterRender();
}
-
- // detach
- internalDetach();
}
}
@@ -2807,7 +2778,7 @@
*
* Called when a request begins.
*/
- protected void internalAttach()
+ public void internalAttach()
{
onAttach();
internalOnAttach();
@@ -2819,7 +2790,7 @@
*
* Called when a request ends.
*/
- protected void internalDetach()
+ public void internalDetach()
{
internalOnDetach();
onDetach();
Modified: incubator/wicket/trunk/wicket/src/main/java/wicket/Page.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/Page.java?view=diff&rev=491143&r1=491142&r2=491143
==============================================================================
--- incubator/wicket/trunk/wicket/src/main/java/wicket/Page.java (original)
+++ incubator/wicket/trunk/wicket/src/main/java/wicket/Page.java Fri Dec 29
16:54:00 2006
@@ -182,7 +182,7 @@
private IPageVersionManager<T> versionManager;
private transient boolean attached = false;
-
+
/**
* Constructor.
*/
@@ -764,11 +764,20 @@
@Override
public void internalDetach()
{
- if(attached )
- {
+ /*
+ * FIXME ivaynberg: i am disabling this check because
components can be
+ * attached without the page itself being attached (like during
page
+ * render), but it is convinient to call internaldetach() on
the page to
+ * cascade the detach call to all components
+ *
+ * i think this check should be moved into each component, not
just be
+ * in the page
+ */
+ //if (attached)
+ //{
super.internalDetach();
attached = false;
- }
+ //}
}
/**
@@ -777,7 +786,7 @@
@Override
public void internalAttach()
{
- if(!attached)
+ if (!attached)
{
super.internalAttach();
attached = true;
Modified:
incubator/wicket/trunk/wicket/src/main/java/wicket/ajax/AjaxRequestTarget.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/ajax/AjaxRequestTarget.java?view=diff&rev=491143&r1=491142&r2=491143
==============================================================================
---
incubator/wicket/trunk/wicket/src/main/java/wicket/ajax/AjaxRequestTarget.java
(original)
+++
incubator/wicket/trunk/wicket/src/main/java/wicket/ajax/AjaxRequestTarget.java
Fri Dec 29 16:54:00 2006
@@ -18,8 +18,10 @@
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -27,9 +29,12 @@
import wicket.Application;
import wicket.Component;
import wicket.IRequestTarget;
+import wicket.MarkupContainer;
import wicket.Page;
import wicket.RequestCycle;
import wicket.Response;
+import wicket.Component.IVisitor;
+import wicket.feedback.IFeedback;
import wicket.markup.html.IHeaderResponse;
import wicket.markup.html.internal.HeaderResponse;
import wicket.protocol.http.WebResponse;
@@ -89,12 +94,16 @@
*/
public final void addComponent(Component component)
{
- if (component==null) {
+ if (component == null)
+ {
throw new IllegalArgumentException("component cannot be
null");
}
- if
(component.getOutputMarkupId()==false&&!component.getMarkupAttributes().containsKey("id"))
+ if (component.getOutputMarkupId() == false
+ &&
!component.getMarkupAttributes().containsKey("id"))
{
- throw new IllegalArgumentException("cannot update
component that does not have setOutputMarkupId property set to true or id
attribute set in its markup attributes. Component: "+component.toString());
+ throw new IllegalArgumentException(
+ "cannot update component that does not
have setOutputMarkupId property set to true or id attribute set in its markup
attributes. Component: "
+ + component.toString());
}
addComponent(component, component.getMarkupId());
}
@@ -236,14 +245,7 @@
respondInvocation(response, js);
}
- for (Map.Entry<String, Component> entry :
markupIdToComponent.entrySet())
- {
- final Component component = entry.getValue();
- final String markupId = entry.getKey();
-
- // render the component
- respondComponent(response, markupId, component);
- }
+ respondComponents(response);
for (String js : appendJavascripts)
{
@@ -266,6 +268,78 @@
}
/**
+ * Processes components added to the target. This involves attaching
+ * components, rendering markup into a client side xml envelope, and
+ * detaching them
+ *
+ * @param response
+ */
+ private void respondComponents(WebResponse response)
+ {
+ Iterator it;
+
+ try
+ {
+ // process feedback
+ it = markupIdToComponent.entrySet().iterator();
+ while (it.hasNext())
+ {
+ final Component component =
(Component)((Entry)it.next()).getValue();
+ if (component instanceof MarkupContainer)
+ {
+ MarkupContainer container =
(MarkupContainer)component;
+
+ // collect feedback
+
container.visitChildren(IFeedback.class, new IVisitor()
+ {
+ public Object
component(Component component)
+ {
+
((IFeedback)component).updateFeedback();
+ return
IVisitor.CONTINUE_TRAVERSAL;
+ }
+ });
+ }
+
+ if (component instanceof IFeedback)
+ {
+ ((IFeedback)component).updateFeedback();
+ }
+ }
+
+ // attach components
+ it = markupIdToComponent.entrySet().iterator();
+ while (it.hasNext())
+ {
+ final Component component =
(Component)((Entry)it.next()).getValue();
+ component.internalAttach();
+ }
+
+ // process component markup
+ it = markupIdToComponent.entrySet().iterator();
+ while (it.hasNext())
+ {
+ final Map.Entry entry = (Entry)it.next();
+ final Component component =
(Component)entry.getValue();
+ final String markupId = (String)entry.getKey();
+
+ respondComponent(response, markupId, component);
+ }
+
+ }
+ finally
+ {
+ // detach
+ it = markupIdToComponent.entrySet().iterator();
+ if (it.hasNext())
+ {
+ final Component component =
(Component)((Entry)it.next()).getValue();
+ component.getPage().internalDetach();
+ }
+ }
+ }
+
+
+ /**
* @see java.lang.Object#toString()
*/
@Override
@@ -335,7 +409,7 @@
}
component.setOutputMarkupId(true);
-
+
// Initialize temporary variables
final Page page = component.getPage();
if (page == null)
@@ -348,7 +422,7 @@
page.setVersioned(false);
page.startComponentRender(component);
-
+
// render any associated headers of the component
respondHeaderContribution(response, component);
@@ -356,7 +430,7 @@
try
{
RequestCycle.get().setResponse(componentResponse);
-
+
component.renderComponent();
}
finally
@@ -392,7 +466,7 @@
private void respondHeaderContribution(final Response response, final
Component component)
{
Response encodingResponse = new StringResponse();
-
+
try
{
final IHeaderResponse headerResponse = new
HeaderResponse(encodingResponse);
@@ -405,11 +479,11 @@
}
String data = encodingResponse.toString();
-
+
if (data.length() != 0)
{
- response.write("<header-contribution");
-
+ response.write("<header-contribution");
+
if (needsEncoding(encodingResponse.toString()))
{
response.write(" encoding=\"");
Modified:
incubator/wicket/trunk/wicket/src/main/java/wicket/request/target/component/ComponentRequestTarget.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/request/target/component/ComponentRequestTarget.java?view=diff&rev=491143&r1=491142&r2=491143
==============================================================================
---
incubator/wicket/trunk/wicket/src/main/java/wicket/request/target/component/ComponentRequestTarget.java
(original)
+++
incubator/wicket/trunk/wicket/src/main/java/wicket/request/target/component/ComponentRequestTarget.java
Fri Dec 29 16:54:00 2006
@@ -19,8 +19,11 @@
package wicket.request.target.component;
import wicket.Component;
+import wicket.MarkupContainer;
import wicket.Page;
import wicket.RequestCycle;
+import wicket.Component.IVisitor;
+import wicket.feedback.IFeedback;
/**
* Default implementation of
@@ -71,8 +74,40 @@
else
{
// Render the component
- component.renderComponent();
-
+ try
+ {
+ // collect feedback
+ if (component instanceof MarkupContainer)
+ {
+ MarkupContainer container =
(MarkupContainer)component;
+
+
container.visitChildren(IFeedback.class, new IVisitor()
+ {
+ public Object
component(Component component)
+ {
+
((IFeedback)component).updateFeedback();
+ return
IVisitor.CONTINUE_TRAVERSAL;
+ }
+ });
+ }
+
+ if (component instanceof IFeedback)
+ {
+ ((IFeedback)component).updateFeedback();
+ }
+
+ // attach
+ component.internalAttach();
+
+ // Render the component
+ component.renderComponent();
+ }
+ finally
+ {
+ component.getPage().internalDetach();
+ }
+
+
if (page != null)
{
page.endComponentRender(component);