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/11/24 02:54:05 UTC
svn commit: r1038436 - in
/wicket/trunk/wicket/src/main/java/org/apache/wicket: ./ behavior/
request/handler/
Author: ivaynberg
Date: Wed Nov 24 01:54:05 2010
New Revision: 1038436
URL: http://svn.apache.org/viewvc?rev=1038436&view=rev
Log:
Issue: WICKET-3098
Added:
wicket/trunk/wicket/src/main/java/org/apache/wicket/request/handler/ListenerInvocationNotAllowedException.java (with props)
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/DefaultExceptionMapper.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/RequestListenerInterface.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/behavior/AbstractBehavior.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/behavior/IBehavior.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/request/handler/ListenerInterfaceRequestHandler.java
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/DefaultExceptionMapper.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/DefaultExceptionMapper.java?rev=1038436&r1=1038435&r2=1038436&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/DefaultExceptionMapper.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/DefaultExceptionMapper.java Wed Nov 24 01:54:05 2010
@@ -25,6 +25,7 @@ import org.apache.wicket.request.Request
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.handler.EmptyRequestHandler;
import org.apache.wicket.request.handler.IPageRequestHandler;
+import org.apache.wicket.request.handler.ListenerInvocationNotAllowedException;
import org.apache.wicket.request.handler.PageProvider;
import org.apache.wicket.request.handler.RenderPageRequestHandler;
import org.apache.wicket.request.http.WebRequest;
@@ -85,7 +86,8 @@ public class DefaultExceptionMapper impl
.getApplicationSettings()
.getPageExpiredErrorPage()));
}
- else if (e instanceof AuthorizationException)
+ else if (e instanceof AuthorizationException ||
+ e instanceof ListenerInvocationNotAllowedException)
{
return createPageRequestHandler(new PageProvider(Application.get()
.getApplicationSettings()
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/RequestListenerInterface.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/RequestListenerInterface.java?rev=1038436&r1=1038435&r2=1038436&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/RequestListenerInterface.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/RequestListenerInterface.java Wed Nov 24 01:54:05 2010
@@ -27,6 +27,7 @@ import org.apache.wicket.authorization.A
import org.apache.wicket.behavior.IBehavior;
import org.apache.wicket.request.RequestHandlerStack.ReplaceHandlerException;
import org.apache.wicket.request.component.IRequestableComponent;
+import org.apache.wicket.request.handler.ListenerInvocationNotAllowedException;
import org.apache.wicket.util.lang.Classes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -191,20 +192,26 @@ public class RequestListenerInterface
*
* @param page
* The Page that contains the component
- * @param component
+ * @param rcomponent
* The component
+ *
+ * @throws ListenerInvocationNotAllowedException
+ * when listener invocation attempted on a component that does not allow it
*/
- public final void invoke(final IRequestableComponent component)
+ public final void invoke(final IRequestableComponent rcomponent)
{
+ // we are in Wicket core land
+ final Component component = (Component)rcomponent;
+
if (!component.canCallListenerInterface())
{
// just return so that we have a silent fail and just re-render the
// page
log.info("component not enabled or visible; ignoring call. Component: " + component);
- return;
+ throw new ListenerInvocationNotAllowedException(this, component, null,
+ "Component rejected interface invocation");
}
-
try
{
// Invoke the interface method on the component
@@ -237,25 +244,23 @@ public class RequestListenerInterface
/**
* Invokes a given interface on a component's behavior.
*
- * @param component
+ * @param rcomponent
* The component
* @param behavior
+ * @throws ListenerInvocationNotAllowedException
+ * when listener invocation attempted on a component that does not allow it
*/
- public final void invoke(final IRequestableComponent component, final IBehavior behavior)
+ public final void invoke(final IRequestableComponent rcomponent, final IBehavior behavior)
{
- if (!component.canCallListenerInterface())
- {
- // just return so that we have a silent fail and just re-render the page
- log.warn("component not enabled or visible; ignoring call. Component: " + component);
- return;
- }
+ // we are in Wicket core land
+ final Component component = (Component)rcomponent;
- // XXX a bit of an ugly cast here from IRequestableComponent to Component
- if (!behavior.isEnabled((Component)component))
+ if (!behavior.canCallListenerInterface(component))
{
log.warn("behavior not enabled; ignore call. Behavior {} at component {}", behavior,
component);
- return;
+ throw new ListenerInvocationNotAllowedException(this, component, behavior,
+ "Behavior rejected interface invocation");
}
try
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/behavior/AbstractBehavior.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/behavior/AbstractBehavior.java?rev=1038436&r1=1038435&r2=1038436&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/behavior/AbstractBehavior.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/behavior/AbstractBehavior.java Wed Nov 24 01:54:05 2010
@@ -167,4 +167,16 @@ public abstract class AbstractBehavior i
public void renderHead(IHeaderResponse response)
{
}
+
+ /**
+ * Checks if a listener can be invoked on this behavior. By checks that both
+ * {@link Component#canCallListenerInterface()} and {@link #isEnabled(Component)} return true.
+ *
+ * @param component
+ * @return true if a listener interface can be invoked on this behavior
+ */
+ public boolean canCallListenerInterface(Component component)
+ {
+ return component.canCallListenerInterface() && isEnabled(component);
+ }
}
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/behavior/IBehavior.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/behavior/IBehavior.java?rev=1038436&r1=1038435&r2=1038436&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/behavior/IBehavior.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/behavior/IBehavior.java Wed Nov 24 01:54:05 2010
@@ -150,4 +150,12 @@ public interface IBehavior extends IClus
* @return true if this behavior is temporary
*/
boolean isTemporary();
+
+ /**
+ * Checks if a listener can be invoked on this behavior
+ *
+ * @param component
+ * @return true if a listener interface can be invoked on this behavior
+ */
+ boolean canCallListenerInterface(Component component);
}
\ No newline at end of file
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=1038436&r1=1038435&r2=1038436&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 Nov 24 01:54:05 2010
@@ -58,7 +58,7 @@ public class ListenerInterfaceRequestHan
this.pageComponentProvider = pageComponentProvider;
this.listenerInterface = listenerInterface;
- this.behaviorId = behaviorIndex;
+ behaviorId = behaviorIndex;
}
/**
@@ -200,7 +200,7 @@ public class ListenerInterfaceRequestHan
}
catch (IndexOutOfBoundsException e)
{
- throw new WicketRuntimeException("Couldn't find component behavior.");
+ throw new WicketRuntimeException("Couldn't find component behavior.", e);
}
}
Added: wicket/trunk/wicket/src/main/java/org/apache/wicket/request/handler/ListenerInvocationNotAllowedException.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/request/handler/ListenerInvocationNotAllowedException.java?rev=1038436&view=auto
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/request/handler/ListenerInvocationNotAllowedException.java (added)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/request/handler/ListenerInvocationNotAllowedException.java Wed Nov 24 01:54:05 2010
@@ -0,0 +1,84 @@
+/*
+ * 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.handler;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.RequestListenerInterface;
+import org.apache.wicket.behavior.IBehavior;
+
+/**
+ * Thrown when a listener invocation is attempted on a component or behavior that does not allow it.
+ * For example, somehow the user attempted to invoke link's onclick method on a disabled link.
+ *
+ * @author igor
+ */
+public class ListenerInvocationNotAllowedException extends RuntimeException
+{
+ private static final long serialVersionUID = 1L;
+
+ private final Component component;
+ private final IBehavior behavior;
+ private final RequestListenerInterface iface;
+
+ /**
+ * Constructor
+ *
+ * @param iface
+ * @param component
+ * @param behavior
+ * @param message
+ */
+ public ListenerInvocationNotAllowedException(RequestListenerInterface iface,
+ Component component, IBehavior behavior, String message)
+ {
+ super(message + detail(iface, component, behavior));
+ this.iface = iface;
+ this.component = component;
+ this.behavior = behavior;
+
+ }
+
+ private static String detail(RequestListenerInterface iface, Component component,
+ IBehavior behavior)
+ {
+ StringBuilder detail = new StringBuilder("Component: ").append(component.toString(false));
+ if (behavior != null)
+ {
+ detail.append(" Behavior: ").append(behavior.toString());
+ }
+ detail.append(" Listener: ").append(iface.toString());
+ return detail.toString();
+ }
+
+ /**
+ * @return component that was the target of invocation or hosted the behavior that was
+ */
+ public Component getComponent()
+ {
+ return component;
+ }
+
+ /**
+ * @return behavior that was the target of invocation or {@code null}
+ */
+ public IBehavior getBehavior()
+ {
+ return behavior;
+ }
+
+
+}
Propchange: wicket/trunk/wicket/src/main/java/org/apache/wicket/request/handler/ListenerInvocationNotAllowedException.java
------------------------------------------------------------------------------
svn:mime-type = text/plain