click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r953970 - in /click/trunk/click/framework/src/org/apache/click: Behavior.java Callback.java ajax/ ajax/AjaxBehavior.java
Date Sat, 12 Jun 2010 09:34:53 GMT
Author: sabob
Date: Sat Jun 12 09:34:53 2010
New Revision: 953970

URL: http://svn.apache.org/viewvc?rev=953970&view=rev
Log:
added main Ajax abstractions. CLK-653

Added:
    click/trunk/click/framework/src/org/apache/click/Behavior.java
    click/trunk/click/framework/src/org/apache/click/Callback.java
    click/trunk/click/framework/src/org/apache/click/ajax/
    click/trunk/click/framework/src/org/apache/click/ajax/AjaxBehavior.java

Added: click/trunk/click/framework/src/org/apache/click/Behavior.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/Behavior.java?rev=953970&view=auto
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/Behavior.java (added)
+++ click/trunk/click/framework/src/org/apache/click/Behavior.java Sat Jun 12 09:34:53 2010
@@ -0,0 +1,87 @@
+/*
+ * 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.click;
+
+/**
+ * Behaviors are added to Controls to provide enhanced features such as
+ * Ajax. Behaviors extend the {@link Callback} interface which
+ * allows them to <tt>decorate</tt> their associated Controls.
+ *
+ * <p/>
+ * Behaviors expose a listener method through
+ * {@link #onAction(org.apache.click.Control)}, which Click will invoke if
+ * the method {@link #isRequestTarget(org.apache.click.Context)} returns true.
+ */
+public interface Behavior extends Callback {
+
+    /**
+     * The behavior action method.
+     *
+     * TODO: javadoc
+     *
+     * @param source the control the behavior is attached to
+     * @return the partial
+     */
+    public Partial onAction(Control source);
+
+    /**
+     * Return true if the behavior is the requeset target, false otherwise.
+     * <p/>
+     * This method is queried by Click to determine if the behavior's
+     * {@link #onAction(org.apache.click.Control)} method should be called in
+     * response to a request.
+     * <p/>
+     * By exposing this method through the Behavior interface it provides
+     * implementers fine grained control over when a behavior should be the
+     * request target.
+     * <p/>
+     * Example below:
+     *
+     * <pre class="prettyprint">
+     * public CustomBehavior implements Behavior {
+     *
+     *     private String eventType;
+     *
+     *     public CustomBehavior(String eventType) {
+     *         // The event type of the behavior
+     *         super(eventType);
+     *     }
+     *
+     *     public boolean isRequestTarget(Context context) {
+     *         // Retrieve the eventType parameter from the incoming request
+     *         String eventType = context.getRequestParameter("type");
+     *
+     *         // Check if this Behavior's eventType matches the request
+     *         // "type" parameter
+     *         return StringUtils.equalsIgnoreCase(this.eventType, eventType);
+     *     }
+     *
+     *     public Partial onAction(Control source) {
+     *         // If isRequestTarget returned true, the onAction method will be
+     *         // invoked
+     *         ...
+     *     }
+     * } </pre>
+     *
+     * @param context the request context
+     * @return true if the behavior is the request target, false otherwise
+     */
+    // TODO move this method to another interface/class?
+    public boolean isRequestTarget(Context context);
+}

Added: click/trunk/click/framework/src/org/apache/click/Callback.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/Callback.java?rev=953970&view=auto
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/Callback.java (added)
+++ click/trunk/click/framework/src/org/apache/click/Callback.java Sat Jun 12 09:34:53 2010
@@ -0,0 +1,56 @@
+/*
+ * 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.click;
+
+/**
+ * TODO use a more suitable classname than Callback?
+ *
+ * Provides a callback for Control life cycle events. The following callbacks are defined:
+ * <ul>
+ * <li>preResponse - occurs before the control markup is written to the response</li>
+ * <li>preGetHeadElements - occurs after <tt>preResponse</tt> but before
the control
+ * {@link Control#getHeadElements() HEAD elements} are written to the response</li>
+ * <li>preDestroy - occurs before the Control {@link Control#onDestroy() onDestroy}
event handler.</li>
+ * </ul>
+ */
+public interface Callback {
+
+    /**
+     * This callback occurs before the markup is written to the
+     * HttpServletResponse.
+     *
+     * @param source the callback's control
+     */
+    public void preResponse(Control source);
+
+    /**
+     * This callback occurs after {@link #preResponse(org.apache.click.Control)},
+     * but before the Control's {@link Control#getHeadElements()} is called.
+     *
+     * @param source the callback's control
+     */
+    public void preGetHeadElements(Control source);
+
+    /**
+     * This callback occurs before the Control's {@link Control#onDestroy()} event handler.
+     *
+     * @param source the callback's control
+     */
+    public void preDestroy(Control source);
+}

Added: click/trunk/click/framework/src/org/apache/click/ajax/AjaxBehavior.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/ajax/AjaxBehavior.java?rev=953970&view=auto
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/ajax/AjaxBehavior.java (added)
+++ click/trunk/click/framework/src/org/apache/click/ajax/AjaxBehavior.java Sat Jun 12 09:34:53
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.click.ajax;
+
+import java.io.Serializable;
+import org.apache.click.Behavior;
+import org.apache.click.Context;
+import org.apache.click.Control;
+
+/**
+ * Provides an abstract implementation of the Behavior interface.
+ *
+ * TODO: javadoc
+ */
+public abstract class AjaxBehavior implements Behavior, Serializable {
+
+    // Constants --------------------------------------------------------------
+
+    private static final long serialVersionUID = 1L;
+
+    // Variables --------------------------------------------------------------
+
+    protected boolean headElementsProcessed = false;
+
+    // Behavior Methods--------------------------------------------------------
+
+    /**
+     * TODO: javadoc
+     *
+     * @param context
+     * @return
+     */
+    public boolean isRequestTarget(Context context) {
+        return true;
+    }
+
+    // Callback Methods -------------------------------------------------------
+
+    /**
+     *
+     * @param source
+     */
+    public void preResponse(Control source) {
+    }
+
+    public void preGetHeadElements(Control source) {
+        // Guard against adding HEAD elements to more than one control
+        if (headElementsProcessed) {
+            return;
+        }
+
+        addHeadElements(source);
+
+        headElementsProcessed = true;
+    }
+
+    public void preDestroy(Control source) {
+        headElementsProcessed = false;
+    }
+
+    // Protected methods ------------------------------------------------------
+
+    protected void addHeadElements(Control source) {
+        // Subclasses can override the default to add head specific elements
+        // NOTE: if this method is ever made public the headElementsProcessed
+        // check should be done here
+    }
+}



Mime
View raw message