You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2005/09/06 01:29:21 UTC

svn commit: r278884 - in /beehive/trunk: docs/forrest/release/src/documentation/content/xdocs/ docs/forrest/release/src/documentation/content/xdocs/netui/ samples/netui-samples/ samples/netui-samples/ui/cellrepeater/

Author: ekoneil
Date: Mon Sep  5 16:29:15 2005
New Revision: 278884

URL: http://svn.apache.org/viewcvs?rev=278884&view=rev
Log:
Add basic documentation on the repeater and the cell repeater.

BB: self
DRT: build.dist pass


Added:
    beehive/trunk/samples/netui-samples/ui/cellrepeater/
    beehive/trunk/samples/netui-samples/ui/cellrepeater/Controller.java   (with props)
    beehive/trunk/samples/netui-samples/ui/cellrepeater/index.jsp   (with props)
Modified:
    beehive/trunk/docs/forrest/release/src/documentation/content/xdocs/netui/repeater.xml
    beehive/trunk/docs/forrest/release/src/documentation/content/xdocs/site.xml
    beehive/trunk/samples/netui-samples/index.jsp

Modified: beehive/trunk/docs/forrest/release/src/documentation/content/xdocs/netui/repeater.xml
URL: http://svn.apache.org/viewcvs/beehive/trunk/docs/forrest/release/src/documentation/content/xdocs/netui/repeater.xml?rev=278884&r1=278883&r2=278884&view=diff
==============================================================================
--- beehive/trunk/docs/forrest/release/src/documentation/content/xdocs/netui/repeater.xml (original)
+++ beehive/trunk/docs/forrest/release/src/documentation/content/xdocs/netui/repeater.xml Mon Sep  5 16:29:15 2005
@@ -1,29 +1,135 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V2.0//EN" "http://forrest.apache.org/dtd/document-v20.dtd">
 
-<!--
-  This template can be used as the starting point for authoring Beehive documentation.  Just remember
-  to author the Forrest subset of XHTML.  More information can be found here:
-
-    http://forrest.apache.org/docs_0_70/index.html    
-
-  -->
 <document>
     <header>
-        <title>Repeater Tags</title>
+        <title>Repeating JSP Tags</title>
     </header>
     <body>
         <section id="overview">
             <title>Overview</title>
             <p>
-            Overview
+            The NetUI JSP tag library contains a set of JSP tags used to repeat over a data set rendering 
+            HTML markup for each item in the set.  There are three sets of these tags:
             </p>
+            <ul>
+            <li>Repeater -- used to render table rows, lists, and other repeating blocks of markup</li>
+            <li>Cell Repeater --  used to render markup in cells of a table of fixed or variable size</li>
+            <li>Data Grid -- used to render complex pageable, sortable, filterable data grids</li>
+            </ul>
         </section>
-        <section id="data-read-only">
-            <title>Displaying Read-only Data</title>
+        <section id="repeater">
+            <title>Repeater</title>
             <p>
-            The <code>&lt;netui-data;repeater></code> tag can be used...
+            The repeater is used similar to a <code>for</code> loop for iterating over a data set.  In general, the repeater
+            renders blocks of markup repeatedly for each item in a data set.  It is also possible to create a header and footer
+            inside of the repeater that render before and after the data set is rendered, respectively.  Each of these regions
+            is offset from the others by JSP tags that mark <em>rendering boundaries</em> inside of the repeater.  Repeaters
+            are often used to render table rows, ordered and unordered lists, repeating <code>div</code>s and so on.  The 
+            <a href="#cellRepeater">cell repeater</a> is useful for repeating over a data set to render table cells, and the 
+            <a href="site:pageflow/tags/datagrid">data grid</a> is useful for rendering complex data sets.  In the simple cases of 
+            displaying read-only data, the repeater is similar to the JSTL <code>forEach</code> tag.  In complex read / write
+            cases, the repeater can participate with the other NetUI tags to create UI for editing entire data sets.  For example,
+            the repeater can be used to render HTML for editing quantities of items in a shopping cart.  
             </p>
+        <section id="readOnlyData">
+            <title>Read only Data</title>
+            <p>
+            The repeater binds to a data set using its <code>dataSource</code> attribute.  The simplest repeater would render
+            a TODO list as an unordered list like:
+            </p>
+            <source><![CDATA[
+                <%@ taglib uri="http://beehive.apache.org/netui/tags-databinding-1.0" prefix="netui-data"%>
+                <ul>
+                <netui-data:repeater dataSource="pageSource.todoList">
+                    <li>${container.item.taskName} -- ${container.item.description}</li>
+                </netui-data:repeater>
+                <ul>
+            ]]></source>
+            <p> 
+            The <code>container</code> implicit object is available for data binding with the JSP 2.0 Expression Language
+            and contains several properties including <code>index</code> and <code>item</code> which provide access to the
+            index of the current item in the data set and to the current data item, respectively.
+            </p>
+            <p>
+            A header and footer can be added to the repeater by using the <code>repeaterHeader</code> and the <code>repeaterFooter</code>
+            tags.  For example, the above unordered list could be encapsulated in the <code>repeater</code> as:
+            </p>
+            <source><![CDATA[
+                <%@ taglib uri="http://beehive.apache.org/netui/tags-databinding-1.0" prefix="netui-data"%>
+                <netui-data:repeater dataSource="pageSource.todoList">
+                    <netui-data:repeaterHeader>
+                        <ul>
+                    <netui-data:repeaterHeader>
+                    <netui-data:repeaterItem>
+                        <li>${container.item.taskName} -- ${container.item.description}</li>
+                    <netui-data:repeaterItem>
+                    <netui-data:repeaterFooter>
+                        </ul>
+                    <netui-data:repeaterFooter>
+                </netui-data:repeater>
+            ]]></source>
+            <p>
+            The repeater can also display a default message when no data is available by setting the <code>defaultText</code>
+            attribute.  Additionally, when rendering sparse data sets, it is often useful to ignore null members; this
+            can be enabled by setting the <code>ignoreNulls</code> attribute to <code>true</code>.
+            </p>
+        </section>
+        <section id="readWriteData">
+            <title>Read / write Data</title>
+            <p>
+            The repeater tags can also be used to render read / write HTML markup.  A simple example is displaying a user interface
+            to change the quantity of each item in a shopping cart.  The <code>samples/netui-samples/ui/repeaterediting/</code>
+            sample in a Beehive distribution contains such an example.  In this sample, the repeater appears as:
+            </p>
+            <source><![CDATA[
+              <netui:form action="update">
+              <netui-data:repeater dataSource="actionForm.items">
+              <tr>
+                  <td>${container.item.name}</td>
+                  <td>
+                      <netui:span value="${container.item.price}">
+                          <netui:formatNumber pattern="$#####.00"/>
+                      </netui:span>
+                  </td>
+                  <td>
+                      <netui:textBox dataSource="container.item.quantity" size="5"/><br/>
+                      <font size="2" color="#ee0000"><netui:error key="invalidQuantity${container.index}"/></font>
+                  </td>
+                  <td>
+                      <netui:checkBox dataSource="container.item.giftWrap"/>
+                  </td>
+              </tr>
+              </netui-data:repeater>
+              </netui:form>
+            ]]></source>
+            <p>
+            In this sample, the repeater binds to an array of <code>Item</code> objects with a set of simple JavaBean properties
+            <code>price</code>, <code>quantity</code>, and <code>giftWrap</code>.  The <code>quantity</code> and <code>giftWrap</code>
+            properties are rendered using the <code>&lt;netui:textBox></code> tag and <code>&lt;netui:checkBox></code> tags which 
+            allow the browser to edit the values of those properties when the page POSTs.  
+            </p>
+            <p>
+            This is possible because the NetUI form element tags work in cooperation with the repeater to rewrite expressions such
+            as <code>container.item.giftWrap</code> into an expression that is used for the name of a check box in the form 
+            <code>actionForm.items[1].giftWrap</code>.  The value of <code>container.index</code> for each item in the array is used
+            to index into the <code>actionForm.items</code> array, and the property <code>giftWrap</code> is added to the end to form 
+            the new expression.  The result is an expression that can POST to the server and can be used to look-up a specific form
+            property on a specific item in the <code>Item</code> JavaBean array.
+            </p>
+        </section>
+        </section>
+        <section id="cellRepeater">
+            <title>Cell Repeater</title>
+            <p>
+            The cell repeater is a JSP tag that is used to render the contents of each cell in an HTML table.  This user interface
+            pattern is common in catalogs and shopping carts and is often used to display a single item per cell.  The cell
+            repeater can be constrained to render a table with a fixed length, a fixed width, or both a fixed length and width.
+            For example, the following sample will display a table of PetBean objects, one per cell in a table four cells wide:
+            </p>
+            <source><![CDATA[
+                
+            ]]></source>
         </section>
     </body>
 </document>

Modified: beehive/trunk/docs/forrest/release/src/documentation/content/xdocs/site.xml
URL: http://svn.apache.org/viewcvs/beehive/trunk/docs/forrest/release/src/documentation/content/xdocs/site.xml?rev=278884&r1=278883&r2=278884&view=diff
==============================================================================
--- beehive/trunk/docs/forrest/release/src/documentation/content/xdocs/site.xml (original)
+++ beehive/trunk/docs/forrest/release/src/documentation/content/xdocs/site.xml Mon Sep  5 16:29:15 2005
@@ -65,7 +65,6 @@
                     <pageflow_tag_repeating_radiobuttongroup href="#RadioButtonGroup" />
                     <pageflow_tag_repeating_select href="#Select" />
                 </pageflow_tag_repeating>
-                <repeater label="Repeater" href="netui/repeater.html"/>
                 <pageflow_tag_xhtml label="HTML/XHTML Support" href="netui/tagsXhtml.html">
                     <pageflow_tagsXhtml_HtmlTag href="#HtmlTag" />
                     <pageflow_tagsXhtml_BodyTag href="#BodyTag" />
@@ -76,6 +75,7 @@
                     <pageflow_tagsJavascript_ScriptBlock href="#ScriptBlock" />
                 </pageflow_tag_javascript>
                 <pageflow_tag_tree label="Trees" href="netui/tagsTree.html" />
+                <repeater label="Repeater" href="netui/repeater.html"/>
                 <datagrid label="Data Grids" href="netui/datagrid.html"/>
                 <pageflow_template label="Templates" href="netui/tagsTemplate.html" />
             </tags>

Modified: beehive/trunk/samples/netui-samples/index.jsp
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/netui-samples/index.jsp?rev=278884&r1=278883&r2=278884&view=diff
==============================================================================
--- beehive/trunk/samples/netui-samples/index.jsp (original)
+++ beehive/trunk/samples/netui-samples/index.jsp Mon Sep  5 16:29:15 2005
@@ -25,7 +25,7 @@
   <netui-template:section name="main">
       <p>
           The following samples demonstrate a variety of
-          <netui:anchor href="http://incubator.apache.org/beehive" value="Beehive"/> NetUI features.
+          <netui:anchor href="http://beehive.apache.org" value="Beehive"/> NetUI features.
       </p>
       <br/>
       <b>NetUI Page Flow Core</b>
@@ -93,6 +93,10 @@
       <dl>
           <dt><netui:anchor href="ui/repeaterediting/Controller.jpf" value="Editing a Data Set using the Repeater"/></dt>
           <dd>Demonstrates how to use a repeater tag to edit text / boolean properties of items in a repeated data set with the repeater</dd>
+      </dl>
+      <dl>
+          <dt><netui:anchor href="ui/cellrepeater/index.jsp" value="Cell repeater"/></dt>
+          <dd>Demonstrates use of the cell repeater to render the contents of cells in an HTML table</dd>
       </dl>
       <dl>
           <dt><netui:anchor href="ui/datagrid/index.jsp" value="Data Grid"/></dt>

Added: beehive/trunk/samples/netui-samples/ui/cellrepeater/Controller.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/netui-samples/ui/cellrepeater/Controller.java?rev=278884&view=auto
==============================================================================
--- beehive/trunk/samples/netui-samples/ui/cellrepeater/Controller.java (added)
+++ beehive/trunk/samples/netui-samples/ui/cellrepeater/Controller.java Mon Sep  5 16:29:15 2005
@@ -0,0 +1,180 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+package ui.cellrepeater;
+
+import java.io.Serializable;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.beehive.controls.api.bean.Control;
+import org.apache.beehive.netui.pageflow.annotations.Jpf;
+import org.apache.beehive.netui.pageflow.PageFlowController;
+import org.apache.beehive.netui.pageflow.Forward;
+import org.apache.beehive.netui.pageflow.FormData;
+import org.apache.beehive.samples.controls.pets.Pets;
+import org.apache.beehive.samples.netui.beans.PetType;
+
+import org.apache.struts.action.ActionErrors;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.ActionMessage;
+
+/**
+ */
+@Jpf.Controller(
+    messageBundles={
+        @Jpf.MessageBundle(bundlePath="org.apache.beehive.samples.netui.resources.repeaterediting.messages")
+    },
+    forwards=@Jpf.Forward(name="success", path="index.jsp")
+)
+public class Controller
+    extends PageFlowController {
+
+    private static final double GIFT_WRAP_PRICE = 4.95;
+
+    @Control()
+    private Pets _petControl;
+
+    private CartForm _cartForm;
+
+    @Jpf.Action(
+        forwards=
+            @Jpf.Forward(name="success", path="index.jsp",
+                actionOutputs=@Jpf.ActionOutput(name="totalPrice", type=java.lang.Double.class))
+    )
+    public Forward begin() {
+        PetType[] pets = _petControl.getPetList();
+        CartItem[] items = new CartItem[pets.length];
+        for(int i = 0; i < items.length; i++) {
+            items[i] = new PetCartItem(pets[i]);
+            items[i].setQuantity(1);
+            items[i].setGiftWrap(false);
+        }
+
+        _cartForm = new CartForm(items);
+
+        Forward forward = new Forward("success");
+        forward.addOutputForm(_cartForm);
+        forward.addActionOutput("totalPrice", calculatePrice(_cartForm.getItems()));
+        return forward;
+    }
+
+    @Jpf.Action(
+        useFormBean="_cartForm",
+        validationErrorForward=@Jpf.Forward(name="failure", navigateTo=Jpf.NavigateTo.currentPage)
+    )
+    public Forward update(CartForm cart) {
+        Forward forward = new Forward("success");
+        forward.addOutputForm(cart);
+        forward.addActionOutput("totalPrice", calculatePrice(cart.getItems()));
+        return forward;
+    }
+
+    private double calculatePrice(CartItem[] items) {
+        double price = 0.0;
+        for(CartItem item : items) {
+            price += item.getQuantity() * item.getPrice();
+            if(item.isGiftWrap())
+                price += GIFT_WRAP_PRICE;
+        }
+        return price;
+    }
+
+    public static class CartForm
+        extends FormData
+        implements Serializable {
+
+        private CartItem[] _items;
+
+        public CartForm() {}
+
+        public CartForm(CartItem[] items) {
+            _items = items;
+        }
+
+        public CartItem[] getItems() {
+            return _items;
+        }
+
+        public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
+            ActionErrors errors = new ActionErrors();
+
+            for(int i = 0; i < _items.length; i++) {
+                CartItem item = _items[i];
+                if(item.getQuantity() <= 0) {
+                    errors.add("invalidQuantity" + i, new ActionMessage("invalidquantity", item.getQuantity()));
+                }
+            }
+
+            return errors;
+        }
+    }
+
+    public static abstract class CartItem
+        implements Serializable {
+
+        private int _quantity;
+        private boolean _giftWrap;
+
+        public int getQuantity() {
+            return _quantity;
+        }
+
+        public void setQuantity(int quantity) {
+            _quantity = quantity;
+        }
+
+        public boolean isGiftWrap() {
+            return _giftWrap;
+        }
+
+        public void setGiftWrap(boolean giftWrap) {
+            _giftWrap = giftWrap;
+        }
+
+        public abstract double getPrice();
+    }
+
+    public static class PetCartItem
+        extends CartItem {
+
+        private PetType _pet;
+
+        public PetCartItem(PetType pet) {
+            _pet = pet;
+        }
+
+        public int getPetId() {
+            assert _pet != null;
+            return _pet.getPetId();
+        }
+
+        public String getName() {
+            assert _pet != null;
+            return _pet.getName();
+        }
+
+        public double getPrice() {
+            assert _pet != null;
+            return _pet.getPrice();
+        }
+
+        public String getDescription() {
+            assert _pet != null;
+            return _pet.getDescription();
+        }
+    }
+}

Propchange: beehive/trunk/samples/netui-samples/ui/cellrepeater/Controller.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: beehive/trunk/samples/netui-samples/ui/cellrepeater/index.jsp
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/netui-samples/ui/cellrepeater/index.jsp?rev=278884&view=auto
==============================================================================
--- beehive/trunk/samples/netui-samples/ui/cellrepeater/index.jsp (added)
+++ beehive/trunk/samples/netui-samples/ui/cellrepeater/index.jsp Mon Sep  5 16:29:15 2005
@@ -0,0 +1,36 @@
+<%--
+   Copyright 2004-2005 The Apache Software Foundation.
+
+   Licensed 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.
+
+   $Header:$
+--%>
+<%@ page language="java" contentType="text/html;charset=UTF-8"%>
+<%@ taglib uri="http://beehive.apache.org/netui/tags-databinding-1.0" prefix="netui-data"%>
+<%@ taglib uri="http://beehive.apache.org/netui/tags-html-1.0" prefix="netui"%>
+<%@ taglib uri="http://beehive.apache.org/netui/tags-template-1.0" prefix="netui-template"%>
+<%@ taglib prefix="sampledata" tagdir="/WEB-INF/tags/data" %>
+
+<netui-template:template templatePage="/resources/template/template.jsp">
+  <netui-template:setAttribute name="sampleTitle" value="Cell Repeater"/>
+  <netui-template:section name="main">
+    <sampledata:petdata/>
+    <br/>
+    <netui-data:cellRepeater dataSource="pageScope.pets" columns="2">
+        ID: <netui:span value="${container.item.petId}"/><br/>
+        Name: <netui:span value="${container.item.name}"/><br/>
+        Description: <netui:span value="${container.item.description}"/><br/>
+        Price: <netui:span value="${container.item.price}"/><br/>
+    </netui-data:cellRepeater>
+  </netui-template:section>
+</netui-template:template>

Propchange: beehive/trunk/samples/netui-samples/ui/cellrepeater/index.jsp
------------------------------------------------------------------------------
    svn:eol-style = native