You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by sa...@apache.org on 2010/10/23 04:52:50 UTC
svn commit: r1026547 - in
/click/trunk/click/examples/src/org/apache/click/examples/page:
introduction/AdvancedTable.java table/SearchTablePage.java
table/TableStyles.java
Author: sabob
Date: Sat Oct 23 02:52:50 2010
New Revision: 1026547
URL: http://svn.apache.org/viewvc?rev=1026547&view=rev
Log:
converted stateful pages to light-weight stateful controls. CLK-715
Modified:
click/trunk/click/examples/src/org/apache/click/examples/page/introduction/AdvancedTable.java
click/trunk/click/examples/src/org/apache/click/examples/page/table/SearchTablePage.java
click/trunk/click/examples/src/org/apache/click/examples/page/table/TableStyles.java
Modified: click/trunk/click/examples/src/org/apache/click/examples/page/introduction/AdvancedTable.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/introduction/AdvancedTable.java?rev=1026547&r1=1026546&r2=1026547&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/introduction/AdvancedTable.java (original)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/introduction/AdvancedTable.java Sat Oct 23 02:52:50 2010
@@ -19,6 +19,8 @@
package org.apache.click.examples.page.introduction;
import java.util.List;
+import org.apache.click.ActionListener;
+import org.apache.click.Control;
import org.apache.click.control.AbstractLink;
import org.apache.click.control.ActionLink;
@@ -57,9 +59,6 @@ public class AdvancedTable extends Borde
// 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);
@@ -109,6 +108,27 @@ public class AdvancedTable extends Borde
return true;
}
+ @Override
+ public void onInit() {
+ super.onInit();
+
+ // Restore the table sort and paging state from the session
+ table.restoreState(getContext());
+
+ table.getControlLink().setActionListener(new ActionListener() {
+
+ public boolean onAction(Control source) {
+ // Save Table sort and paging state between requests.
+ // NOTE: we set the listener on the table's Link control which is invoked
+ // when the Link is clicked, such as when paging or sorting.
+ // This ensures the table state is only saved when the state changes, and
+ // cuts down on unnecessary session replication in a cluster environment.
+ table.saveState(getContext());
+ return true;
+ }
+ });
+ }
+
// Public Methods ---------------------------------------------------------
/**
Modified: click/trunk/click/examples/src/org/apache/click/examples/page/table/SearchTablePage.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/table/SearchTablePage.java?rev=1026547&r1=1026546&r2=1026547&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/table/SearchTablePage.java (original)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/table/SearchTablePage.java Sat Oct 23 02:52:50 2010
@@ -19,6 +19,9 @@
package org.apache.click.examples.page.table;
import java.util.List;
+import org.apache.click.ActionListener;
+import org.apache.click.Context;
+import org.apache.click.Control;
import org.apache.click.control.AbstractLink;
import org.apache.click.control.ActionLink;
@@ -64,13 +67,11 @@ public class SearchTablePage extends Bor
// Constructor ------------------------------------------------------------
public SearchTablePage() {
- setStateful(true);
-
// Setup the search form
form.setColumns(2);
form.add(nameField);
form.add(dateField);
- form.add(new Submit("Search"));
+ form.add(new Submit("Search", this, "onSearchClick"));
form.add(new Submit("Clear", this, "onClearClick"));
form.add(new SpacerButton());
form.add(new Submit("New...", this, "onNewClick"));
@@ -128,14 +129,61 @@ public class SearchTablePage extends Bor
// Event Handlers ---------------------------------------------------------
+ @Override
+ public void onInit() {
+ super.onInit();
+ Context context = getContext();
+
+ // Restore form and table state from the session
+ form.restoreState(context);
+ table.restoreState(context);
+
+ table.getControlLink().setActionListener(new ActionListener() {
+ public boolean onAction(Control source) {
+ // Save Table sort and paging state between requests.
+ // NOTE: we set the listener on the table's Link control which is invoked
+ // when the Link is clicked, such as when paging or sorting.
+ // This ensures the table state is only saved when the state changes, and
+ // cuts down on unnecessary session replication in a cluster environment.
+ table.saveState(getContext());
+ return true;
+ }
+ });
+
+ }
+
+ /**
+ * Handle the search button click event.
+ *
+ * @return true
+ */
+ public boolean onSearchClick() {
+ // Save Form search field value between requests.
+ // NOTE: we only save the from when the search button is clicked.
+ // This ensures the form state is only saved when the state changes, and
+ // cuts down on unnecessary session replication in a cluster environment.
+ form.saveState(getContext());
+ return true;
+ }
+
/**
* Handle the clear button click event.
*
* @return true
*/
public boolean onClearClick() {
+ // Clear field values
form.clearErrors();
form.clearValues();
+
+ // Clear table state
+ table.setPageNumber(0);
+ table.setSortedColumn(null);
+
+ // Remove table and form state from the session
+ Context context = getContext();
+ form.removeState(context);
+ table.removeState(context);
return true;
}
Modified: click/trunk/click/examples/src/org/apache/click/examples/page/table/TableStyles.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/table/TableStyles.java?rev=1026547&r1=1026546&r2=1026547&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/table/TableStyles.java (original)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/table/TableStyles.java Sat Oct 23 02:52:50 2010
@@ -30,7 +30,6 @@ import org.apache.click.examples.domain.
import org.apache.click.examples.page.BorderPage;
import org.apache.click.examples.service.CustomerService;
import org.apache.click.extras.control.TableInlinePaginator;
-import org.apache.click.util.Bindable;
import org.apache.click.dataprovider.DataProvider;
/**
@@ -40,25 +39,19 @@ public class TableStyles extends BorderP
private static final long serialVersionUID = 1L;
- @Bindable protected Form form = new Form();
- @Bindable protected Table table = new Table();
+ private Form form = new Form("form");
+ private Table table = new Table("table");
private Select styleSelect = new Select("style", "Table Style:");
private Checkbox hoverCheckbox = new Checkbox("hover", "Hover Rows:");
- /**
- * Spring injected CustomerService bean. The service is marked as transient
- * since the page is stateful and we don't want to serialize the service
- * along with the page.
- */
- private transient CustomerService customerService;
+ private CustomerService customerService;
// Constructor -----------------------------------------------------------
public TableStyles() {
- // Store form's selection data in the session so is data will be
- // available after table control GET requests have been processed
- setStateful(true);
+ addControl(form);
+ addControl(table);
// Setup table style select.
form.setColumns(3);
@@ -73,6 +66,9 @@ public class TableStyles extends BorderP
hoverCheckbox.setAttribute("onclick", "form.submit();");
form.add(hoverCheckbox);
+ // Rexstore form's selection data from the session
+ form.restoreState(getContext());
+
// Setup customers table
table.setClass(styleSelect.getValue());
table.setHoverRows(true);
@@ -118,6 +114,16 @@ public class TableStyles extends BorderP
// Event Handlers ---------------------------------------------------------
/**
+ * @see org.apache.click.Page#onPost()
+ */
+ @Override
+ public void onPost() {
+ // Save the posted form data in the session, so this data will be
+ // available for future requests
+ form.saveState(getContext());
+ }
+
+ /**
* @see org.apache.click.Page#onRender()
*/
@Override
@@ -129,7 +135,7 @@ public class TableStyles extends BorderP
// Public Methods ---------------------------------------------------------
/**
- * Return CustomerService instance from Spring application context.
+ * Return CustomerService instance.
*
* @return CustomerService instance
*/
@@ -138,7 +144,8 @@ public class TableStyles extends BorderP
}
/**
- * Set the CustomerService instance from Spring application context.
+ * Set the CustomerService instance that is injected by the Spring
+ * application context.
*
* @param customerService the customerService instance to inject
*/