click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r789872 - in /incubator/click/trunk/click: documentation/xdocs/src/docbook/click/chapter-introduction.xml examples/src/org/apache/click/examples/page/EditCustomer.java examples/src/org/apache/click/examples/page/introduction/AdvancedTable.java
Date Tue, 30 Jun 2009 18:47:03 GMT
Author: sabob
Date: Tue Jun 30 18:47:03 2009
New Revision: 789872

URL: http://svn.apache.org/viewvc?rev=789872&view=rev
Log:
stateful advanced table page

Modified:
    incubator/click/trunk/click/documentation/xdocs/src/docbook/click/chapter-introduction.xml
    incubator/click/trunk/click/examples/src/org/apache/click/examples/page/EditCustomer.java
    incubator/click/trunk/click/examples/src/org/apache/click/examples/page/introduction/AdvancedTable.java

Modified: incubator/click/trunk/click/documentation/xdocs/src/docbook/click/chapter-introduction.xml
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/documentation/xdocs/src/docbook/click/chapter-introduction.xml?rev=789872&r1=789871&r2=789872&view=diff
==============================================================================
--- incubator/click/trunk/click/documentation/xdocs/src/docbook/click/chapter-introduction.xml
(original)
+++ incubator/click/trunk/click/documentation/xdocs/src/docbook/click/chapter-introduction.xml
Tue Jun 30 18:47:03 2009
@@ -442,8 +442,11 @@
     @Bindable public ActionLink deleteLink = new ActionLink("Delete", this, "onDeleteClick");
 
     // ------------------------------------- Constructor
-     
+
     public CustomersPage() {
+        // Set Page to stateful to preserve Table sort and paging state while editing customers
+        setStateful(true); <co id="co-stateful-table" linkends="ca-stateful-table"/>
+
         table.setClass(Table.CLASS_ITS);
         table.setPageSize(10);
         table.setShowBanner(true);
@@ -498,11 +501,25 @@
     }
 }</programlisting>
 
+    <calloutlist>
+      <callout arearefs="co-stateful-table" id="ca-stateful-table">
+        <para>Setting Page to stateful instructs Click to store the Page in the
+        <ulink url="http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/http/HttpSession.html">HttpSession</ulink>.
+        This ensures the Table's sort and paging state is preserved while editing
+        customers. See the <link linkend="stateful-pages">Stateful Page</link>
+        section for more details.
+        </para>
+      </callout>
+    </calloutlist>
+
     <para>In this Page code example a Table control is declared and a number of
     <ulink url="../../click-api/org/apache/click/control/Column.html">Column</ulink>
-    objects are added. A deleteLink
+    objects are added. An editLink
+    <ulink url="../../click-api/org/apache/click/control/PageLink.html">PageLink</ulink>
+    control is used as decorator for the "Action" column. This control navigates
+    to the <classname>EditCustomer</classname> page. A deleteLink
     <ulink url="../../click-api/org/apache/click/control/ActionLink.html">ActionLink</ulink>
-    control is used as a decorator for the "Action" column. This control will
+    control is also used as a decorator for the "Action" column. This control will
     invoke the Page <methodname>onDeleteClick()</methodname> method when it is
     clicked. Finally we have the Page <methodname>onRender()</methodname> method
     which is used to populate the Table control with rows before it is rendered.
@@ -537,7 +554,9 @@
       </mediaobject>
     </figure>
 
-    <para>In this example if a user click on the Delete link, the
+    <para>In this example, clicking on the Edit link will navigate the user to
+    the <classname>EditCustomer</classname> page where the selected customer
+    can be edited. When the user click on the Delete link, the
     <methodname>onDeleteClick()</methodname> method will be called on the Page
     deleting the customer record.
     </para>

Modified: incubator/click/trunk/click/examples/src/org/apache/click/examples/page/EditCustomer.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/page/EditCustomer.java?rev=789872&r1=789871&r2=789872&view=diff
==============================================================================
--- incubator/click/trunk/click/examples/src/org/apache/click/examples/page/EditCustomer.java
(original)
+++ incubator/click/trunk/click/examples/src/org/apache/click/examples/page/EditCustomer.java
Tue Jun 30 18:47:03 2009
@@ -18,18 +18,14 @@
  */
 package org.apache.click.examples.page;
 
-import java.util.HashMap;
-import java.util.Map;
 import javax.annotation.Resource;
 
 import org.apache.click.Page;
-import org.apache.click.control.ActionLink;
 import org.apache.click.control.Checkbox;
 import org.apache.click.control.FieldSet;
 import org.apache.click.control.Form;
 import org.apache.click.control.HiddenField;
 import org.apache.click.control.Submit;
-import org.apache.click.control.Table;
 import org.apache.click.control.TextField;
 import org.apache.click.examples.control.InvestmentSelect;
 import org.apache.click.examples.domain.Customer;
@@ -60,11 +56,6 @@
 
     // Public variables can automatically have their value set by request parameters
     @Bindable public Integer id;
-    @Bindable public String actionLink;
-    @Bindable public int page;
-    @Bindable public String column;
-    @Bindable public boolean ascending;
-    @Bindable public boolean sort;
 
     private HiddenField idField = new HiddenField("id", Integer.class);
 
@@ -111,13 +102,6 @@
      */
     @Override
     public void onGet() {
-        // Store the Page public properties state in hidden fields
-        form.add(new HiddenField(Table.PAGE, page));
-        form.add(new HiddenField(Table.COLUMN, column));
-        form.add(new HiddenField(Table.ASCENDING, ascending));
-        form.add(new HiddenField(Table.SORT, sort));
-        form.add(new HiddenField(ActionLink.ACTION_LINK, actionLink));
-
         if (id != null) {
             Customer customer = customerService.getCustomerForID(id);
 
@@ -141,14 +125,7 @@
 
             String referrer = referrerField.getValue();
             if (referrer != null) {
-                // Pass the Page public properties to the referring page
-                Map params = new HashMap();
-                params.put(Table.PAGE, page);
-                params.put(Table.COLUMN, column);
-                params.put(Table.SORT, sort);
-                params.put(Table.ASCENDING, ascending);
-                params.put(ActionLink.ACTION_LINK, actionLink);
-                setRedirect(referrer, params);
+                setRedirect(referrer);
             } else {
                 setRedirect(HomePage.class);
             }

Modified: incubator/click/trunk/click/examples/src/org/apache/click/examples/page/introduction/AdvancedTable.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/page/introduction/AdvancedTable.java?rev=789872&r1=789871&r2=789872&view=diff
==============================================================================
--- incubator/click/trunk/click/examples/src/org/apache/click/examples/page/introduction/AdvancedTable.java
(original)
+++ incubator/click/trunk/click/examples/src/org/apache/click/examples/page/introduction/AdvancedTable.java
Tue Jun 30 18:47:03 2009
@@ -20,8 +20,6 @@
 
 import java.util.List;
 
-import javax.annotation.Resource;
-
 import org.apache.click.Page;
 import org.apache.click.control.AbstractLink;
 import org.apache.click.control.ActionLink;
@@ -33,26 +31,38 @@
 import org.apache.click.examples.service.CustomerService;
 import org.apache.click.extras.control.LinkDecorator;
 import org.apache.click.util.Bindable;
-import org.springframework.stereotype.Component;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
 
 /**
  * Provides an advanced Table usage example Page.
+ * <p/>
+ * This example also demonstrates how a stateful Page can be used to preserve
+ * the Table sort and paging state while editing customers.
  *
  * @author Malcolm Edgar
  */
-@Component
-public class AdvancedTable extends BorderPage {
+public class AdvancedTable extends BorderPage implements ApplicationContextAware {
+
+    private static final long serialVersionUID = 1L;
 
     @Bindable public Table table = new Table();
     @Bindable public PageLink editLink = new PageLink("Edit", EditCustomer.class);
     @Bindable public ActionLink deleteLink = new ActionLink("Delete", this, "onDeleteClick");
 
-    @Resource(name="customerService")
-    private CustomerService customerService;
+    /**
+     * Spring's application context from where a CustomerService instance can be
+     * retrieved.
+     */
+    private transient ApplicationContext applicationContext;
 
     // ------------------------------------------------------------ Constructor
 
     public AdvancedTable() {
+        // Set Page to stateful to preserve Table sort and paging state while editing customers
+        setStateful(true);
+
         table.setClass(Table.CLASS_ITS);
         table.setPageSize(10);
         table.setShowBanner(true);
@@ -89,7 +99,7 @@
 
     public boolean onDeleteClick() {
         Integer id = deleteLink.getValueInteger();
-        customerService.deleteCustomer(id);
+        getCustomerService().deleteCustomer(id);
         return true;
     }
 
@@ -98,15 +108,27 @@
      */
     @Override
     public void onRender() {
-        List list = customerService.getCustomers();
+        List list = getCustomerService().getCustomers();
         table.setRowList(list);
+    }
 
-        // Pass the Table paging and sorting parameters to the link's target
-        // page: 'EditCustomer'
-        editLink.setParameter(Table.PAGE, String.valueOf(table.getPageNumber()));
-        editLink.setParameter(Table.COLUMN, table.getSortedColumn());
-        editLink.setParameter(Table.SORT, Boolean.toString(table.isSorted()));
-        editLink.setParameter(Table.ASCENDING, Boolean.toString(table.isSortedAscending()));
-        editLink.setParameter(ActionLink.ACTION_LINK, table.getControlLink().getName());
+    /**
+     * Return CustomerService instance from Spring application context.
+     *
+     * @return CustomerService instance
+     */
+    public CustomerService getCustomerService() {
+        return (CustomerService) applicationContext.getBean("customerService");
+    }
+
+    /**
+     * Set Spring application context as defined by
+     * {@link org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)}.
+     *
+     * @param applicationContext set Spring application context
+     */
+    public void setApplicationContext(ApplicationContext applicationContext)
+        throws BeansException {
+        this.applicationContext = applicationContext;
     }
 }



Mime
View raw message