You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2010/10/13 20:37:38 UTC
svn commit: r1022229 - in /wicket/trunk/wicket/src:
main/java/org/apache/wicket/ main/java/org/apache/wicket/request/component/
main/java/org/apache/wicket/request/handler/ test/java/org/apache/wicket/
test/java/org/apache/wicket/ajax/markup/html/compo...
Author: ivaynberg
Date: Wed Oct 13 18:37:37 2010
New Revision: 1022229
URL: http://svn.apache.org/viewvc?rev=1022229&view=rev
Log:
isTemporary behavior and ajax behavior together crashes with WicketRuntimeException: Couldn't find component behavior.
Issue: WICKET-3097
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/Component.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/request/component/IRequestableComponent.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/request/handler/ListenerInterfaceRequestHandler.java
wicket/trunk/wicket/src/test/java/org/apache/wicket/MockComponent.java
wicket/trunk/wicket/src/test/java/org/apache/wicket/TestDetachPageAjaxResult.html
wicket/trunk/wicket/src/test/java/org/apache/wicket/TestDetachPageExpectedResult.html
wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/componentMap/SimpleTestPageExpectedResult-1.html
wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/componentMap/SimpleTestPageExpectedResult.html
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePageExpectedResult_13.html
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/Component.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/Component.java?rev=1022229&r1=1022228&r2=1022229&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/Component.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/Component.java Wed Oct 13 18:37:37 2010
@@ -596,6 +596,27 @@ public abstract class Component
}
}
+ private boolean data_can_remove(int index)
+ {
+ int len = data_length();
+ for (int j = index + 1; j < len; j++)
+ {
+ if (data_get(j) instanceof IRequestListener)
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * WARNING: CALL THIS METHOD ONLY IF {@link #data_can_remove(int)} HAS RETURNED {@code true},
+ * OTHERWISE USE {@link #data_set(int, Object)} TO SET THE VALUE TO {@code null} OR SOMETHING
+ * MORE APPROPRIATE FOR THE USECASE
+ *
+ * @param position
+ * @return {@code true} if the item can be removed
+ */
private Object data_remove(int position)
{
int currentLength = data_length();
@@ -1061,16 +1082,19 @@ public abstract class Component
if (data != null)
{
// if the model is set, we must skip it
- final int startIndex = getFlag(FLAG_MODEL_SET) ? 1 : 0;
int length = data_length();
- if (length > startIndex)
+ if (length > 0)
{
final ArrayList<IBehavior> result = new ArrayList<IBehavior>();
- for (int i = startIndex; i < length; ++i)
+ for (int i = 0; i < length; ++i)
{
Object o = data_get(i);
- if (o == null || o instanceof IBehavior)
+ if (o == null || !(o instanceof IBehavior))
+ {
+ result.add((IBehavior)null);
+ }
+ else
{
result.add((IBehavior)o);
}
@@ -1731,6 +1755,20 @@ public abstract class Component
return key.get(getMetaData());
}
+ private int getMetaDataIndex()
+ {
+ int start = getFlag(FLAG_MODEL_SET) ? 1 : 0;
+ for (int i = start; i < data_length(); i++)
+ {
+ Object object = data_get(i);
+ if (object instanceof MetaDataEntry<?>[] || object instanceof MetaDataEntry)
+ {
+ return i;
+ }
+ }
+ return -1;
+ }
+
/**
*
* @return meta data entry
@@ -1740,11 +1778,9 @@ public abstract class Component
MetaDataEntry<?>[] metaData = null;
// index where we should expect the entry
- int index = getFlag(FLAG_MODEL_SET) ? 1 : 0;
-
- int length = data_length();
+ int index = getMetaDataIndex();
- if (index < length)
+ if (index >= 0)
{
Object object = data_get(index);
if (object instanceof MetaDataEntry<?>[])
@@ -2449,17 +2485,8 @@ public abstract class Component
// Instead we check if there are any behaviors downstream that will be affected by
// this, and if there are we set this behavior's slot to null instead of removing it
// to preserve indexes of behaviors downstream.
- boolean anyListenersAfter = false;
- for (int j = i + 1; j < len; j++)
- {
- if (data_get(j) instanceof IRequestListener)
- {
- anyListenersAfter = true;
- break;
- }
- }
- if (anyListenersAfter)
+ if (!data_can_remove(i))
{
data_set(i, null);
}
@@ -3030,6 +3057,7 @@ public abstract class Component
*/
public final <M> void setMetaData(final MetaDataKey<M> key, final M object)
{
+ int index = getMetaDataIndex();
MetaDataEntry<?>[] old = getMetaData();
Object metaData = null;
@@ -3039,11 +3067,9 @@ public abstract class Component
metaData = (metaDataArray.length > 1) ? (Object)metaDataArray : metaDataArray[0];
}
- int index = getFlag(FLAG_MODEL_SET) ? 1 : 0;
-
if (old == null && metaData != null)
{
- data_insert(index, metaData);
+ data_add(metaData);
}
else if (old != null && metaData != null)
{
@@ -3051,7 +3077,15 @@ public abstract class Component
}
else if (old != null && metaData == null)
{
- data_remove(index);
+ if (data_can_remove(index))
+ {
+ data_remove(index);
+ }
+ else
+ {
+ data_set(index, null);
+ }
+
}
}
@@ -3122,8 +3156,15 @@ public abstract class Component
}
else
{
- data_remove(0);
- setFlag(FLAG_MODEL_SET, false);
+ if (data_can_remove(0))
+ {
+ data_remove(0);
+ setFlag(FLAG_MODEL_SET, false);
+ }
+ else
+ {
+ data_set(0, null);
+ }
}
}
else
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/request/component/IRequestableComponent.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/request/component/IRequestableComponent.java?rev=1022229&r1=1022228&r2=1022229&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/request/component/IRequestableComponent.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/request/component/IRequestableComponent.java Wed Oct 13 18:37:37 2010
@@ -72,17 +72,21 @@ public interface IRequestableComponent
* Gets the currently coupled {@link IBehavior}s as a unmodifiable list. Returns an empty list
* rather than null if there are no behaviors coupled to this component.
*
+ * NOTE: the list of behaviors is used to keep the index of the behavior in the url, which means
+ * the list returned should preserve the index. Eg, removal of items from the list should not be
+ * allowed, a removed item should instead be marked by a value such as {@code null}.
+ *
* @return The currently coupled behaviors as a unmodifiable list
*/
- public List<? extends IBehavior> getBehaviors();
+ public List<? extends IBehavior> getBehaviorsRawList();
/**
* Detaches the component.
* <p>
* NOTE: this method is not inherited from {@link IDetachable} on purpose. in Wicket the
* assumption for a long time has been that {@link Component}s do not implement
- * {@link IDetachable}; doing so may lead to some very nasty side-effects. Consider {@code
- * AbstractPropertyModel#detach()} which looks like this:
+ * {@link IDetachable}; doing so may lead to some very nasty side-effects. Consider
+ * {@code AbstractPropertyModel#detach()} which looks like this:
*
* <pre>
* public void detach()
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/request/handler/ListenerInterfaceRequestHandler.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/request/handler/ListenerInterfaceRequestHandler.java?rev=1022229&r1=1022228&r2=1022229&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/request/handler/ListenerInterfaceRequestHandler.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/request/handler/ListenerInterfaceRequestHandler.java Wed Oct 13 18:37:37 2010
@@ -174,7 +174,7 @@ public class ListenerInterfaceRequestHan
}
finally
{
- if(frozen != null)
+ if (frozen != null)
page.setFreezePageId(frozen);
}
}
@@ -187,16 +187,17 @@ public class ListenerInterfaceRequestHan
private void invokeListener()
{
+ IRequestableComponent component = getComponent();
if (getBehaviorIndex() == null)
{
- listenerInterface.invoke(getComponent());
+ listenerInterface.invoke(component);
}
else
{
try
{
- IBehavior behavior = getComponent().getBehaviors().get(behaviorIndex);
- listenerInterface.invoke(getComponent(), behavior);
+ IBehavior behavior = component.getBehaviorsRawList().get(behaviorIndex);
+ listenerInterface.invoke(component, behavior);
}
catch (IndexOutOfBoundsException e)
{
Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/MockComponent.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/MockComponent.java?rev=1022229&r1=1022228&r2=1022229&view=diff
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/MockComponent.java (original)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/MockComponent.java Wed Oct 13 18:37:37 2010
@@ -139,7 +139,7 @@ public class MockComponent implements IR
return true;
}
- public List<IBehavior> getBehaviors()
+ public List<IBehavior> getBehaviorsRawList()
{
return Collections.emptyList();
}
Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/TestDetachPageAjaxResult.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/TestDetachPageAjaxResult.html?rev=1022229&r1=1022228&r2=1022229&view=diff
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/TestDetachPageAjaxResult.html (original)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/TestDetachPageAjaxResult.html Wed Oct 13 18:37:37 2010
@@ -5,6 +5,6 @@
wicketAjaxDebugEnable=true;
/*-->]^]^>*/</script>
<script type="text/javascript" id="wicket-ajax-base-url"><!--/*--><![CDATA[/*><!--*/
-Wicket.Ajax.baseUrl="wicket/page?0-1.IBehaviorListener.0-comp";
+Wicket.Ajax.baseUrl="wicket/page?0-1.IBehaviorListener.1-comp";
/*-->]^]^>*/</script>
-</head>]]></header-contribution><component id="comp1" ><![CDATA[<span id="comp1" onclick="var wcall=wicketAjaxGet('page?0-1.IBehaviorListener.0-comp',function() { }.bind(this),function() { }.bind(this), function() {return Wicket.$('comp1') != null;}.bind(this));">body</span>]]></component></ajax-response>
\ No newline at end of file
+</head>]]></header-contribution><component id="comp1" ><![CDATA[<span id="comp1" onclick="var wcall=wicketAjaxGet('page?0-1.IBehaviorListener.1-comp',function() { }.bind(this),function() { }.bind(this), function() {return Wicket.$('comp1') != null;}.bind(this));">body</span>]]></component></ajax-response>
\ No newline at end of file
Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/TestDetachPageExpectedResult.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/TestDetachPageExpectedResult.html?rev=1022229&r1=1022228&r2=1022229&view=diff
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/TestDetachPageExpectedResult.html (original)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/TestDetachPageExpectedResult.html Wed Oct 13 18:37:37 2010
@@ -9,6 +9,6 @@ wicketAjaxDebugEnable=true;
Wicket.Ajax.baseUrl="wicket/bookmarkable/org.apache.wicket.TestDetachPage?0";
/*-->]]>*/</script>
</head><body>
- <span wicket:id="comp" id="comp1" onclick="var wcall=wicketAjaxGet('../page?0-1.IBehaviorListener.0-comp',function() { }.bind(this),function() { }.bind(this), function() {return Wicket.$('comp1') != null;}.bind(this));">body</span>
+ <span wicket:id="comp" id="comp1" onclick="var wcall=wicketAjaxGet('../page?0-1.IBehaviorListener.1-comp',function() { }.bind(this),function() { }.bind(this), function() {return Wicket.$('comp1') != null;}.bind(this));">body</span>
</body>
</html>
Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/componentMap/SimpleTestPageExpectedResult-1.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/componentMap/SimpleTestPageExpectedResult-1.html?rev=1022229&r1=1022228&r2=1022229&view=diff
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/componentMap/SimpleTestPageExpectedResult-1.html (original)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/componentMap/SimpleTestPageExpectedResult-1.html Wed Oct 13 18:37:37 2010
@@ -5,6 +5,6 @@
wicketAjaxDebugEnable=true;
/*-->]^]^>*/</script>
<script type="text/javascript" id="wicket-ajax-base-url"><!--/*--><![CDATA[/*><!--*/
-Wicket.Ajax.baseUrl="wicket/page?0-1.IBehaviorListener.0-testPanel-baseSpan-linja1";
+Wicket.Ajax.baseUrl="wicket/page?0-1.IBehaviorListener.1-testPanel-baseSpan-linja1";
/*-->]^]^>*/</script>
-</head>]]></header-contribution><component id="linja11" ><![CDATA[<span id="linja11">1</span>]]></component><evaluate><![CDATA[setTimeout("var wcall=wicketAjaxGet('page?0-1.IBehaviorListener.0-testPanel-baseSpan-linja1',function() { }.bind(this),function() { }.bind(this), function() {var c = Wicket.$('linja11'); return typeof(c) != 'undefined' && c != null}.bind(this));", 2000);]]></evaluate></ajax-response>
\ No newline at end of file
+</head>]]></header-contribution><component id="linja11" ><![CDATA[<span id="linja11">1</span>]]></component><evaluate><![CDATA[setTimeout("var wcall=wicketAjaxGet('page?0-1.IBehaviorListener.1-testPanel-baseSpan-linja1',function() { }.bind(this),function() { }.bind(this), function() {var c = Wicket.$('linja11'); return typeof(c) != 'undefined' && c != null}.bind(this));", 2000);]]></evaluate></ajax-response>
\ No newline at end of file
Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/componentMap/SimpleTestPageExpectedResult.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/componentMap/SimpleTestPageExpectedResult.html?rev=1022229&r1=1022228&r2=1022229&view=diff
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/componentMap/SimpleTestPageExpectedResult.html (original)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/markup/html/componentMap/SimpleTestPageExpectedResult.html Wed Oct 13 18:37:37 2010
@@ -11,7 +11,7 @@ wicketAjaxDebugEnable=true;
Wicket.Ajax.baseUrl="wicket/bookmarkable/org.apache.wicket.ajax.markup.html.componentMap.SimpleTestPage?0";
/*-->]]>*/</script>
<script type="text/javascript" ><!--/*--><![CDATA[/*><!--*/
-Wicket.Event.add(window, "load", function(event) { setTimeout("var wcall=wicketAjaxGet('../page?0-1.IBehaviorListener.0-testPanel-baseSpan-linja1',function() { }.bind(this),function() { }.bind(this), function() {var c = Wicket.$('linja11'); return typeof(c) != 'undefined' && c != null}.bind(this));", 2000);;});
+Wicket.Event.add(window, "load", function(event) { setTimeout("var wcall=wicketAjaxGet('../page?0-1.IBehaviorListener.1-testPanel-baseSpan-linja1',function() { }.bind(this),function() { }.bind(this), function() {var c = Wicket.$('linja11'); return typeof(c) != 'undefined' && c != null}.bind(this));", 2000);;});
/*-->]]>*/</script>
</head>
<body>
Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePageExpectedResult_13.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePageExpectedResult_13.html?rev=1022229&r1=1022228&r2=1022229&view=diff
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePageExpectedResult_13.html (original)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePageExpectedResult_13.html Wed Oct 13 18:37:37 2010
@@ -1,7 +1,7 @@
<? xml version= "1.0" encoding ="UTF-8" ?>
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html wicket:id="html" xmlns:wicket="" xmlns="http://www.w3.org/1999/xhtml" xmlns:lang="[current language]" lang="de" id="html1" onclick="var wcall=wicketAjaxGet('../page?0-1.IBehaviorListener.0-html',function() { }.bind(this),function() { }.bind(this), function() {return Wicket.$('html1') != null;}.bind(this));return !wcall;">
+<html wicket:id="html" xmlns:wicket="" xmlns="http://www.w3.org/1999/xhtml" xmlns:lang="[current language]" lang="de" id="html1" onclick="var wcall=wicketAjaxGet('../page?0-1.IBehaviorListener.1-html',function() { }.bind(this),function() { }.bind(this), function() {return Wicket.$('html1') != null;}.bind(this));return !wcall;">
<head><link rel="stylesheet" type="text/css" href="../../BasePage.css" />
<script type="text/javascript" src="../resource/org.apache.wicket.markup.html.WicketEventReference/wicket-event.js"></script>
<script type="text/javascript" src="../resource/org.apache.wicket.ajax.WicketAjaxReference/wicket-ajax.js"></script>