You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2011/09/07 16:58:46 UTC
svn commit: r1166210 - in /wicket/trunk/wicket-core/src:
main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java
main/java/org/apache/wicket/ajax/AjaxChannel.java
test/java/org/apache/wicket/ajax/AjaxChannelTest.java
Author: mgrigorov
Date: Wed Sep 7 14:58:45 2011
New Revision: 1166210
URL: http://svn.apache.org/viewvc?rev=1166210&view=rev
Log:
WICKET-4024 Provide a Convenience API for usage of Ajax Channels
Added:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxChannel.java
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxChannelTest.java
Modified:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java
Modified: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java?rev=1166210&r1=1166209&r2=1166210&view=diff
==============================================================================
--- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java (original)
+++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java Wed Sep 7 14:58:45 2011
@@ -249,8 +249,26 @@ public abstract class AbstractDefaultAja
return call;
}
+ /**
+ * @return the name and the type of the channel to use when processing Ajax calls at the client
+ * side
+ * @deprecated Use {@link #getChannel()} instead
+ */
+ // TODO Wicket 1.6 - Remove this method
+ @Deprecated
protected String getChannelName()
{
+ AjaxChannel channel = getChannel();
+ return channel != null ? channel.getChannelName() : null;
+ }
+
+ /**
+ * Provides an AjaxChannel for this Behavior.
+ *
+ * @return an AjaxChannel - Defaults to null.
+ * */
+ protected AjaxChannel getChannel()
+ {
return null;
}
Added: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxChannel.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxChannel.java?rev=1166210&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxChannel.java (added)
+++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxChannel.java Wed Sep 7 14:58:45 2011
@@ -0,0 +1,115 @@
+/*
+ * 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.IClusterable;
+
+/**
+ * A Channel that used to process Ajax requests.
+ *
+ * Channels are either:
+ * <ul>
+ * <li>queueing - Ajax requests are kept in a Queue at the client side and processed one at a time.
+ * Default.</li>
+ * <li>dropping - only the last Ajax request is processed, the others are discarded</li>
+ * </ul>
+ *
+ * @author Martin Dilger
+ */
+public class AjaxChannel implements IClusterable
+{
+
+ /**
+ * The type of an {@link AjaxChannel}
+ */
+ public static enum Type {
+
+ /**
+ * Ajax requests are kept in a Queue at the client side and processed one at a time
+ */
+ QUEUE,
+
+ /**
+ * dropping - only the last Ajax request is processed, the others are discarded
+ */
+ DROP;
+ }
+
+ private final String name;
+
+ private final Type type;
+
+ /**
+ * Construct.
+ *
+ * @param name
+ */
+ public AjaxChannel(final String name)
+ {
+ this(name, Type.QUEUE);
+ }
+
+ /**
+ * Construct.
+ *
+ * @param name
+ * the name of the channel
+ * @param type
+ * the behavior type of this channel
+ */
+ public AjaxChannel(final String name, final Type type)
+ {
+ this.name = name;
+ this.type = type;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * @return the type of this channel
+ * @see AjaxChannel.Type
+ */
+ public Type getType()
+ {
+ return type;
+ }
+
+ /**
+ * Calculates the ChannelName.
+ *
+ * @return a String in the format channelName|d for DropChannels, channelName|s for Stackable
+ * Channels.
+ */
+ String getChannelName()
+ {
+ return toString();
+ }
+
+ @Override
+ public String toString()
+ {
+ // 's' comes from 'stack', but it really acts as a queue.
+ // TODO Wicket 1.6 - consider renaming it to 'q'
+ return String.format("%s|%s", name, type == Type.QUEUE ? "s" : "d");
+ }
+}
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxChannelTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxChannelTest.java?rev=1166210&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxChannelTest.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxChannelTest.java Wed Sep 7 14:58:45 2011
@@ -0,0 +1,46 @@
+/*
+ * 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.WicketTestCase;
+import org.junit.Test;
+
+/**
+ * @author Martin Dilger
+ */
+public class AjaxChannelTest extends WicketTestCase
+{
+
+ /**
+ * https://issues.apache.org/jira/browse/WICKET-4024
+ */
+ @Test
+ public void getChannelNameRetursCorrectStringForStackableChannels()
+ {
+ String channelName = "channelName";
+ String expectedForStackables = channelName + "|s";
+ String expectedForDrops = channelName + "|d";
+
+ AjaxChannel stackableChannel = new AjaxChannel(channelName, AjaxChannel.Type.QUEUE);
+ AjaxChannel dropChannel = new AjaxChannel(channelName, AjaxChannel.Type.DROP);
+
+ assertEquals(expectedForStackables, stackableChannel.getChannelName());
+ assertEquals(expectedForDrops, dropChannel.getChannelName());
+ }
+
+
+}