You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by ma...@apache.org on 2008/05/01 17:41:23 UTC

svn commit: r652559 - in /wicket: branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/ branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/ trunk/wicket/src/main/java/org/apache/wicket/ajax/ trunk/wicket/src/...

Author: marrink
Date: Thu May  1 08:41:23 2008
New Revision: 652559

URL: http://svn.apache.org/viewvc?rev=652559&view=rev
Log:
RESOLVED - issue WICKET-1575: AjaxEventBehavior does not check for component.isEnableAllowed before adding the ajax event to the tag 
https://issues.apache.org/jira/browse/WICKET-1575

Added:
    wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledPage.html   (with props)
    wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledPage.java   (with props)
    wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledTest.java   (with props)
    wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledPage.html   (with props)
    wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledPage.java   (with props)
    wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledTest.java   (with props)
Modified:
    wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/AjaxEventBehavior.java
    wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/AjaxEventBehavior.java

Modified: wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/AjaxEventBehavior.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/AjaxEventBehavior.java?rev=652559&r1=652558&r2=652559&view=diff
==============================================================================
--- wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/AjaxEventBehavior.java (original)
+++ wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/ajax/AjaxEventBehavior.java Thu May  1 08:41:23 2008
@@ -16,6 +16,7 @@
  */
 package org.apache.wicket.ajax;
 
+import org.apache.wicket.Component;
 import org.apache.wicket.IClusterable;
 import org.apache.wicket.markup.ComponentTag;
 import org.apache.wicket.util.string.Strings;
@@ -103,7 +104,8 @@
 		super.onComponentTag(tag);
 
 		// only add the event handler when the component is enabled.
-		if (getComponent().isEnabled())
+		Component myComponent = getComponent();
+		if (myComponent.isEnabled() && myComponent.isEnableAllowed())
 		{
 			tag.put(event, getEventHandler());
 		}

Added: wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledPage.html
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledPage.html?rev=652559&view=auto
==============================================================================
--- wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledPage.html (added)
+++ wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledPage.html Thu May  1 08:41:23 2008
@@ -0,0 +1,11 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<title>Insert title here</title>
+</head>
+<body>
+	<span wicket:id="enabled"></span>
+	<span wicket:id="disabled"></span>
+</body>
+</html>
\ No newline at end of file

Propchange: wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledPage.html
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledPage.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledPage.java?rev=652559&view=auto
==============================================================================
--- wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledPage.java (added)
+++ wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledPage.java Thu May  1 08:41:23 2008
@@ -0,0 +1,60 @@
+/*
+ * 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;
+
+import junit.framework.Assert;
+
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+
+/**
+ * @author marrink
+ */
+public class AjaxBehaviorEnabledPage extends WebPage
+{
+
+	/**
+	 * Construct.
+	 */
+	public AjaxBehaviorEnabledPage()
+	{
+		Label enabled = new Label("enabled", "this label is ajax enabled");
+		enabled.add(new AjaxEventBehavior("onclick")
+		{
+
+			private static final long serialVersionUID = 1L;
+
+			protected void onEvent(AjaxRequestTarget target)
+			{
+				Assert.assertNotNull(target);
+			}
+		});
+		add(enabled);
+		Label disabled = new Label("disabled", "this label is not ajax enabled");
+		disabled.add(new AjaxEventBehavior("onclick")
+		{
+			private static final long serialVersionUID = 1L;
+
+			protected void onEvent(AjaxRequestTarget target)
+			{
+				Assert.fail("should never get here with disabled ajax");
+			}
+		});
+		add(disabled);
+	}
+
+}

Propchange: wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledPage.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledTest.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledTest.java?rev=652559&view=auto
==============================================================================
--- wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledTest.java (added)
+++ wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledTest.java Thu May  1 08:41:23 2008
@@ -0,0 +1,113 @@
+/*
+ * 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;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.Request;
+import org.apache.wicket.Response;
+import org.apache.wicket.Session;
+import org.apache.wicket.WicketTestCase;
+import org.apache.wicket.authorization.Action;
+import org.apache.wicket.authorization.IAuthorizationStrategy;
+import org.apache.wicket.protocol.http.WebSession;
+import org.apache.wicket.util.tester.WicketTester;
+
+/**
+ * @author marrink
+ */
+public class AjaxBehaviorEnabledTest extends WicketTestCase
+{
+	/**
+	 * Custom security strategy to disable all components where the id ends with "disable".
+	 * 
+	 * @author marrink
+	 */
+	private static final class CustomStrategy implements IAuthorizationStrategy
+	{
+		/**
+		 * 
+		 * @see org.apache.wicket.authorization.IAuthorizationStrategy#isActionAuthorized(org.apache.wicket.Component,
+		 *      org.apache.wicket.authorization.Action)
+		 */
+		public boolean isActionAuthorized(Component component, Action action)
+		{
+			if (action == Component.ENABLE && component.getId().endsWith("disabled"))
+				return false;
+			return true;
+		}
+
+		/**
+		 * 
+		 * @see org.apache.wicket.authorization.IAuthorizationStrategy#isInstantiationAuthorized(java.lang.Class)
+		 */
+		public boolean isInstantiationAuthorized(Class componentClass)
+		{
+			return true;
+		}
+
+	}
+
+	/**
+	 * Construct.
+	 * 
+	 * @param name
+	 */
+	public AjaxBehaviorEnabledTest(String name)
+	{
+		super(name);
+	}
+
+	/**
+	 * @see org.apache.wicket.WicketTestCase#setUp()
+	 */
+	protected void setUp() throws Exception
+	{
+		final IAuthorizationStrategy strategy = new CustomStrategy();
+		tester = new WicketTester(new WicketTester.DummyWebApplication()
+		{
+			public Session newSession(Request request, Response response)
+			{
+				return new WebSession(request)
+				{
+					private static final long serialVersionUID = 1L;
+
+					public IAuthorizationStrategy getAuthorizationStrategy()
+					{
+						return strategy;
+					}
+				};
+			}
+		});
+	}
+
+	/**
+	 * TestCase for bug.
+	 * 
+	 * @see <a href="https://issues.apache.org/jira/browse/WICKET-1575">1575</a>
+	 */
+	public void testDisabledBehavior()
+	{
+		tester.startPage(AjaxBehaviorEnabledPage.class);
+		tester.assertRenderedPage(AjaxBehaviorEnabledPage.class);
+		tester.assertVisible("enabled");
+		tester.assertVisible("disabled");
+		assertTrue(tester.getTagByWicketId("enabled").hasAttribute("onclick"));
+		assertFalse(tester.getTagByWicketId("disabled").hasAttribute("onclick"));
+
+	}
+
+}

Propchange: wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/AjaxEventBehavior.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/AjaxEventBehavior.java?rev=652559&r1=652558&r2=652559&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/AjaxEventBehavior.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/AjaxEventBehavior.java Thu May  1 08:41:23 2008
@@ -16,6 +16,7 @@
  */
 package org.apache.wicket.ajax;
 
+import org.apache.wicket.Component;
 import org.apache.wicket.IClusterable;
 import org.apache.wicket.markup.ComponentTag;
 import org.apache.wicket.util.string.Strings;
@@ -98,12 +99,14 @@
 	 * 
 	 * @see org.apache.wicket.behavior.AbstractAjaxBehavior#onComponentTag(org.apache.wicket.markup.ComponentTag)
 	 */
+	@Override
 	protected void onComponentTag(final ComponentTag tag)
 	{
 		super.onComponentTag(tag);
 
 		// only add the event handler when the component is enabled.
-		if (getComponent().isEnabled())
+		Component< ? > myComponent = getComponent();
+		if (myComponent.isEnabled() && myComponent.isEnableAllowed())
 		{
 			tag.put(event, getEventHandler());
 		}
@@ -123,6 +126,7 @@
 		return handler;
 	}
 
+	@Override
 	protected CharSequence generateCallbackScript(CharSequence partialCall)
 	{
 		CharSequence script = super.generateCallbackScript(partialCall);
@@ -156,6 +160,7 @@
 	 * 
 	 * @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#respond(org.apache.wicket.ajax.AjaxRequestTarget)
 	 */
+	@Override
 	protected final void respond(final AjaxRequestTarget target)
 	{
 		onEvent(target);

Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledPage.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledPage.html?rev=652559&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledPage.html (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledPage.html Thu May  1 08:41:23 2008
@@ -0,0 +1,11 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<title>Insert title here</title>
+</head>
+<body>
+	<span wicket:id="enabled"></span>
+	<span wicket:id="disabled"></span>
+</body>
+</html>
\ No newline at end of file

Propchange: wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledPage.html
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledPage.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledPage.java?rev=652559&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledPage.java (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledPage.java Thu May  1 08:41:23 2008
@@ -0,0 +1,62 @@
+/*
+ * 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;
+
+import junit.framework.Assert;
+
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+
+/**
+ * @author marrink
+ */
+public class AjaxBehaviorEnabledPage extends WebPage
+{
+
+	/**
+	 * Construct.
+	 */
+	public AjaxBehaviorEnabledPage()
+	{
+		Label<String> enabled = new Label<String>("enabled", "this label is ajax enabled");
+		enabled.add(new AjaxEventBehavior("onclick")
+		{
+
+			private static final long serialVersionUID = 1L;
+
+			@Override
+			protected void onEvent(AjaxRequestTarget target)
+			{
+				Assert.assertNotNull(target);
+			}
+		});
+		add(enabled);
+		Label<String> disabled = new Label<String>("disabled", "this label is not ajax enabled");
+		disabled.add(new AjaxEventBehavior("onclick")
+		{
+			private static final long serialVersionUID = 1L;
+
+			@Override
+			protected void onEvent(AjaxRequestTarget target)
+			{
+				Assert.fail("should never get here with disabled ajax");
+			}
+		});
+		add(disabled);
+	}
+
+}

Propchange: wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledPage.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledTest.java?rev=652559&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledTest.java (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledTest.java Thu May  1 08:41:23 2008
@@ -0,0 +1,116 @@
+/*
+ * 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;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.Request;
+import org.apache.wicket.Response;
+import org.apache.wicket.Session;
+import org.apache.wicket.WicketTestCase;
+import org.apache.wicket.authorization.Action;
+import org.apache.wicket.authorization.IAuthorizationStrategy;
+import org.apache.wicket.protocol.http.WebSession;
+import org.apache.wicket.util.tester.WicketTester;
+
+/**
+ * @author marrink
+ */
+public class AjaxBehaviorEnabledTest extends WicketTestCase
+{
+	/**
+	 * Custom security strategy to disable all components where the id ends with "disable".
+	 * 
+	 * @author marrink
+	 */
+	private static final class CustomStrategy implements IAuthorizationStrategy
+	{
+		/**
+		 * 
+		 * @see org.apache.wicket.authorization.IAuthorizationStrategy#isActionAuthorized(org.apache.wicket.Component,
+		 *      org.apache.wicket.authorization.Action)
+		 */
+		public boolean isActionAuthorized(Component< ? > component, Action action)
+		{
+			if (action == Component.ENABLE && component.getId().endsWith("disabled"))
+				return false;
+			return true;
+		}
+
+		/**
+		 * 
+		 * @see org.apache.wicket.authorization.IAuthorizationStrategy#isInstantiationAuthorized(java.lang.Class)
+		 */
+		public boolean isInstantiationAuthorized(Class< ? extends Component> componentClass)
+		{
+			return true;
+		}
+
+	}
+
+	/**
+	 * Construct.
+	 * 
+	 * @param name
+	 */
+	public AjaxBehaviorEnabledTest(String name)
+	{
+		super(name);
+	}
+
+	/**
+	 * @see org.apache.wicket.WicketTestCase#setUp()
+	 */
+	@Override
+	protected void setUp() throws Exception
+	{
+		final IAuthorizationStrategy strategy = new CustomStrategy();
+		tester = new WicketTester(new WicketTester.DummyWebApplication()
+		{
+			@Override
+			public Session newSession(Request request, Response response)
+			{
+				return new WebSession(request)
+				{
+					private static final long serialVersionUID = 1L;
+
+					@Override
+					public IAuthorizationStrategy getAuthorizationStrategy()
+					{
+						return strategy;
+					}
+				};
+			}
+		});
+	}
+
+	/**
+	 * TestCase for bug.
+	 * 
+	 * @see <a href="https://issues.apache.org/jira/browse/WICKET-1575">1575</a>
+	 */
+	public void testDisabledBehavior()
+	{
+		tester.startPage(AjaxBehaviorEnabledPage.class);
+		tester.assertRenderedPage(AjaxBehaviorEnabledPage.class);
+		tester.assertVisible("enabled");
+		tester.assertVisible("disabled");
+		assertTrue(tester.getTagByWicketId("enabled").hasAttribute("onclick"));
+		assertFalse(tester.getTagByWicketId("disabled").hasAttribute("onclick"));
+
+	}
+
+}

Propchange: wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/AjaxBehaviorEnabledTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain