Author: sabob
Date: Thu Jun 11 21:42:17 2009
New Revision: 783932
URL: http://svn.apache.org/viewvc?rev=783932&view=rev
Log:
lookup rather than inject Spring services when using stateful pages
Modified:
incubator/click/trunk/click/examples/src/org/apache/click/examples/page/table/SearchTablePage.java
incubator/click/trunk/click/examples/src/org/apache/click/examples/page/table/TableStyles.java
Modified: incubator/click/trunk/click/examples/src/org/apache/click/examples/page/table/SearchTablePage.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/page/table/SearchTablePage.java?rev=783932&r1=783931&r2=783932&view=diff
==============================================================================
--- incubator/click/trunk/click/examples/src/org/apache/click/examples/page/table/SearchTablePage.java
(original)
+++ incubator/click/trunk/click/examples/src/org/apache/click/examples/page/table/SearchTablePage.java
Thu Jun 11 21:42:17 2009
@@ -21,7 +21,6 @@
import java.io.Serializable;
import java.util.List;
-import javax.annotation.Resource;
import org.apache.click.control.AbstractLink;
import org.apache.click.control.ActionLink;
@@ -40,6 +39,9 @@
import org.apache.click.extras.control.LinkDecorator;
import org.apache.click.extras.control.TableInlinePaginator;
import org.apache.click.util.Bindable;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
/**
@@ -48,7 +50,8 @@
* @author Malcolm Edgar
*/
@Component
-public class SearchTablePage extends BorderPage implements Serializable {
+public class SearchTablePage extends BorderPage implements Serializable,
+ ApplicationContextAware {
private static final long serialVersionUID = 1L;
@@ -60,8 +63,7 @@
private TextField nameField = new TextField(Customer.NAME_PROPERTY);
private DateField dateField = new DateField(Customer.DATE_JOINED_PROPERTY, "Start Date");
- @Resource(name="customerService")
- private transient CustomerService customerService;
+ private transient ApplicationContext applicationContext;
// ----------------------------------------------------------- Constructors
@@ -153,7 +155,7 @@
*/
public boolean onDeleteClick() {
Integer id = deleteLink.getValueInteger();
- customerService.deleteCustomer(id);
+ getCustomerService().deleteCustomer(id);
return true;
}
@@ -163,8 +165,28 @@
@Override
public void onRender() {
List customers =
- customerService.getCustomers(nameField.getValue(), dateField.getDate());
+ getCustomerService().getCustomers(nameField.getValue(), dateField.getDate());
table.setRowList(customers);
}
+
+ /**
+ * 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;
+ }
}
Modified: incubator/click/trunk/click/examples/src/org/apache/click/examples/page/table/TableStyles.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/page/table/TableStyles.java?rev=783932&r1=783931&r2=783932&view=diff
==============================================================================
--- incubator/click/trunk/click/examples/src/org/apache/click/examples/page/table/TableStyles.java
(original)
+++ incubator/click/trunk/click/examples/src/org/apache/click/examples/page/table/TableStyles.java
Thu Jun 11 21:42:17 2009
@@ -18,10 +18,9 @@
*/
package org.apache.click.examples.page.table;
+import java.io.Serializable;
import java.util.List;
-import javax.annotation.Resource;
-
import org.apache.click.control.Checkbox;
import org.apache.click.control.Column;
import org.apache.click.control.Form;
@@ -33,6 +32,9 @@
import org.apache.click.examples.service.CustomerService;
import org.apache.click.extras.control.TableInlinePaginator;
import org.apache.click.util.Bindable;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
/**
@@ -41,7 +43,10 @@
* @author Malcolm Edgar
*/
@Component
-public class TableStyles extends BorderPage {
+public class TableStyles extends BorderPage implements Serializable,
+ ApplicationContextAware {
+
+ private static final long serialVersionUID = 1L;
@Bindable public Form form = new Form();
@Bindable public Table table = new Table();
@@ -49,8 +54,7 @@
private Select styleSelect = new Select("style", "Table Style:");
private Checkbox hoverCheckbox = new Checkbox("hover", "Hover Rows:");
- @Resource(name="customerService")
- private transient CustomerService customerService;
+ private transient ApplicationContext applicationContext;
// ----------------------------------------------------------- Constructor
@@ -116,8 +120,27 @@
table.setClass(styleSelect.getValue());
table.setHoverRows(hoverCheckbox.isChecked());
- List<Customer> customers = customerService.getCustomers();
+ List<Customer> customers = getCustomerService().getCustomers();
table.setRowList(customers);
}
+ /**
+ * 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;
+ }
}
|