click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r964038 - in /click/trunk/click/examples: src/org/apache/click/examples/page/general/ webapp/WEB-INF/ webapp/general/
Date Wed, 14 Jul 2010 13:10:37 GMT
Author: sabob
Date: Wed Jul 14 13:10:37 2010
New Revision: 964038

URL: http://svn.apache.org/viewvc?rev=964038&view=rev
Log:
added PageAction demo for image element

Added:
    click/trunk/click/examples/src/org/apache/click/examples/page/general/PageActionImage.java
    click/trunk/click/examples/src/org/apache/click/examples/page/general/PageActionLink.java
      - copied, changed from r949399, click/trunk/click/examples/src/org/apache/click/examples/page/general/PageAction.java
    click/trunk/click/examples/webapp/general/page-action-image.htm
    click/trunk/click/examples/webapp/general/page-action-link.htm
      - copied, changed from r949395, click/trunk/click/examples/webapp/general/page-action.htm
Removed:
    click/trunk/click/examples/src/org/apache/click/examples/page/general/PageAction.java
    click/trunk/click/examples/webapp/general/page-action.htm
Modified:
    click/trunk/click/examples/webapp/WEB-INF/menu.xml

Added: click/trunk/click/examples/src/org/apache/click/examples/page/general/PageActionImage.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/general/PageActionImage.java?rev=964038&view=auto
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/general/PageActionImage.java
(added)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/general/PageActionImage.java
Wed Jul 14 13:10:37 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.examples.page.general;
+
+import java.io.IOException;
+import java.io.InputStream;
+import javax.servlet.ServletContext;
+import org.apache.click.Context;
+import org.apache.click.Partial;
+import org.apache.click.examples.page.BorderPage;
+import org.apache.click.util.ClickUtils;
+import org.apache.commons.io.IOUtils;
+
+/**
+ * This demo shows to invoke a PAGE_ACTION using an HTML <img> tag. The pageAction
+ * will render the image data to the browser.
+ */
+public class PageActionImage extends BorderPage {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * This page method is invoked from the <img> element and returns a Partial
+     * instance containing the static image data.
+     */
+    public Partial getStaticImageData() {
+        // Load the static image 'click-icon-blue-32.png'
+        byte[] imageData = loadImageData("click-icon-blue-32.png");
+
+        // Lookup the contentType for a PNG image
+        String contentType = ClickUtils.getMimeType("png");
+
+        // Return a Partial containing the image data
+        return new Partial(imageData, contentType);
+    }
+
+    /**
+     * This page method is invoked from the <img> element and returns a Partial
+     * instance containing the image data specified by the imageName parameter.
+     */
+    public Partial getDynamicImageData() {
+        Context context = getContext();
+
+        // Retrieve the image name parameter from the request
+        String imageName = context.getRequestParameter("imageName");
+
+        // Load the static image 'click-icon-blue-32.png'
+        byte[] imageData = loadImageData(imageName);
+
+        // Lookup the contentType for a PNG image
+        String contentType = ClickUtils.getMimeType("png");
+
+        // Return a Partial containing the image data
+        return new Partial(imageData, contentType);
+    }
+
+    private byte[] loadImageData(String imageName) {
+        try {
+            ServletContext servletContext = getContext().getServletContext();
+            InputStream is = servletContext.getResourceAsStream("/assets/images/" + imageName);
+            byte[] imageData = IOUtils.toByteArray(is);
+            return imageData;
+
+        } catch (IOException ioe) {
+            throw new RuntimeException(ioe);
+        }
+    }
+}

Copied: click/trunk/click/examples/src/org/apache/click/examples/page/general/PageActionLink.java
(from r949399, click/trunk/click/examples/src/org/apache/click/examples/page/general/PageAction.java)
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/general/PageActionLink.java?p2=click/trunk/click/examples/src/org/apache/click/examples/page/general/PageActionLink.java&p1=click/trunk/click/examples/src/org/apache/click/examples/page/general/PageAction.java&r1=949399&r2=964038&rev=964038&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/general/PageAction.java
(original)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/general/PageActionLink.java
Wed Jul 14 13:10:37 2010
@@ -23,15 +23,17 @@ import org.apache.click.control.PageLink
 import org.apache.click.examples.page.BorderPage;
 
 /**
- * Provides an Page action demo.
+ * Provides a PageAction demo. The PageLink sets a PAGE_ACTION to the page method
+ * 'getDate'. Clicking on the PageLink will invoke the 'getDate' method and render
+ * the Partial response.
  */
-public class PageAction extends BorderPage {
+public class PageActionLink extends BorderPage {
 
     private static final long serialVersionUID = 1L;
 
-    private PageLink link = new PageLink("link", "Get Date", PageAction.class);
+    private PageLink link = new PageLink("link", "Get Date", PageActionLink.class);
 
-    public PageAction() {
+    public PageActionLink() {
         addControl(link);
 
         // We set a PAGE_ACTION to invoke the getDate method below

Modified: click/trunk/click/examples/webapp/WEB-INF/menu.xml
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/webapp/WEB-INF/menu.xml?rev=964038&r1=964037&r2=964038&view=diff
==============================================================================
--- click/trunk/click/examples/webapp/WEB-INF/menu.xml (original)
+++ click/trunk/click/examples/webapp/WEB-INF/menu.xml Wed Jul 14 13:10:37 2010
@@ -48,10 +48,12 @@
     <menu label="Direct Page" path="general/direct-page.htm" target="_blank"/>
     <menu label="Exception Demo" path="general/exception.htm"/>
     <menu label="Flash Attribute" path="general/flash.htm"/>
-    <menu label="Page Action" path="general/page-action.htm"/>
     <menu label="Page Imports" path="general/page-imports-example.htm"/>
     <menu label="Page Security" path="security/secure.htm"/>
     <menu separator="true"/>
+    <menu label="Page Action Image" path="general/page-action-image.htm"/>
+    <menu label="Page Action Link" path="general/page-action-link.htm"/>
+    <menu separator="true"/>
     <menu label="JSP Hello World" path="jsp/hello-world.htm"/>
     <menu label="JSP Customer Table" path="jsp/customer-table.htm"/>
     <menu label="JSP Form Demo" path="jsp/edit-customer.htm"/>

Added: click/trunk/click/examples/webapp/general/page-action-image.htm
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/webapp/general/page-action-image.htm?rev=964038&view=auto
==============================================================================
--- click/trunk/click/examples/webapp/general/page-action-image.htm (added)
+++ click/trunk/click/examples/webapp/general/page-action-image.htm Wed Jul 14 13:10:37 2010
@@ -0,0 +1,55 @@
+<!--
+#* 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.*#
+-->
+
+Demonstrates how to serve image data through a PageAction. You should see the Click
+logo rendered below:
+
+<p/>
+
+<img src="$context$path?pageAction=getStaticImageData" alt="Retrieve image data through
a Page Action"/>
+
+<p/>
+
+A PageAction is processed
+by passing the parameter <span class="blue">pageAction</span> and a target
+Page method. In this example the Page method is <span class="red">getStaticImageData</span>.
+
+<p/>
+
+<pre class="codeHtml">
+&lt;img src="$context$path?<span class="blue">pageAction</span>=<span
class="red">getStaticImageData</span>"/&gt;</pre>
+
+<h3>Dynamic images</h3>
+
+You can easily load dynamic images by by passing request parameters.
+
+<p/>
+
+<img src="$context$path?pageAction=getDynamicImageData&imageName=home.png" alt="Retrieve
dynamic image data through a Page Action"/>
+
+<p/>
+
+In this demo we pass to the server the name of the image to load. The parameter
+<span class="blue">imageName</span> controls which image to load, in this example
+<span class="red">home.png</span>.
+
+<p/>
+
+<pre class="codeHtml">
+&lt;img src="$context$path?pageAction=getDynamicImageData&<span class="blue">imageName</span>=<span
class="red">home.png</span>"/&gt;</pre>

Copied: click/trunk/click/examples/webapp/general/page-action-link.htm (from r949395, click/trunk/click/examples/webapp/general/page-action.htm)
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/webapp/general/page-action-link.htm?p2=click/trunk/click/examples/webapp/general/page-action-link.htm&p1=click/trunk/click/examples/webapp/general/page-action.htm&r1=949395&r2=964038&rev=964038&view=diff
==============================================================================
--- click/trunk/click/examples/webapp/general/page-action.htm (original)
+++ click/trunk/click/examples/webapp/general/page-action-link.htm Wed Jul 14 13:10:37 2010
@@ -1 +1,20 @@
+<!--
+#* 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.*#
+-->
+
 $link
\ No newline at end of file



Mime
View raw message