|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.servlet.GenericServlet javax.servlet.http.HttpServlet net.sf.click.ClickServlet net.sf.click.extras.spring.SpringClickServlet
Provides an Spring framework integration SpringClickServlet.
This Spring integration servlet provides a number of integration options using Spring with Click pages. These options detailed below.customer-list.htm -> com.mycorp.page.CustomerListPage -> customerListPage HTML Request Click Page Class Spring Bean NameIf the page bean is not found in the ApplicationContxt then the full Page class name is used.
customer-list.htm -> com.mycorp.page.CustomerListPage -> com.mycorp.page.CustomerListPage HTML Request Click Page Class Spring Bean NameThis integration option requires you to configure all your Spring Page beans in your Spring XML configuration. While this may be quite laborious, it does support Spring 1.x and Java 1.4. An example page bean configuration is provided below:
<?xml version="1.0" encoding="UTF-8"?> <beans> <bean id="customerListPage" class="com.mycorp.page.CustomerListPage" scope="prototype"/> </beans>Please Note ensure the page beans scope is set to "prototype" so a new \ page instance will be created with every HTTP request. Otherwise Spring will default to using singletons and your code will not be thread safe.
package com.mycorp.page; import net.sf.click.Page; import com.mycorp.service.CustomerService; public class CustomerListPage extends Page { private CustomerService customerService; public void setCustomerService(CustomerService customerService) { this.customerService = customerService; } .. }Page property bean name must match the bean name defined in the Spring XML configuration. Continuing our example the Spring XML configuration is provided below:
<?xml version="1.0" encoding="UTF-8"?> <beans> <bean id="customerService" class="com.mycorp.service.CustomerService"/> </beans>This option will also automatically inject the ApplicationContext into new page instances which implement the
ApplicationContextAware
interface. Using the applicationContext you can lookup Spring beans manually
in your pages. For example:
public class CustomerListPage extends Page implements ApplicationContextAware { protected ApplicationContext applicationContext; public void setApplicationContext(ApplicationContext applicationContext) { this.applicationContext = applicationContext; } public CustomerService getCustomerService() { return (CustomerService) applicationContext.getBean("customerService"); } }This last strategy is probably the least convenient integration option.
WebApplicationContextUtils
which is configured with a
ContextLoaderListener
. For example:
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>SpringClickServlet</servlet-name>
<servlet-class>net.sf.click.extras.spring.SpringClickServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
..
</web-app>
Alternatively you can specify the path to the ApplicationContext as a
servlet init parameter. For example:
<?xml version="1.0" encoding="UTF-8"?> <web-app> <servlet> <servlet-name>SpringClickServlet</servlet-name> <servlet-class>net.sf.click.extras.spring.SpringClickServlet</servlet-class> <init-param> <param-name>spring-path</param-name> <param-value>/applicationContext.xml</param-value> </init-param> <load-on-startup>0</load-on-startup> </servlet> .. </web-app>To configure page Spring bean injection you need to configure the inject-page-beans servlet init parameter. For example:
<?xml version="1.0" encoding="UTF-8"?> <web-app> .. <servlet> <servlet-name>SpringClickServlet</servlet-name> <servlet-class>net.sf.click.extras.spring.SpringClickServlet</servlet-class> <init-param> <param-name>inject-page-beans</param-name> <param-value>true</param-value> </init-param> <load-on-startup>0</load-on-startup> </servlet> .. </web-app>
Field Summary | |
protected ApplicationContext |
applicationContext
Spring application context bean factory. |
static String |
INJECT_PAGE_BEANS
The Servlet initialization parameter name for the option to have the SpringClickServlet inject Spring beans into page instances: "inject-page-beans". |
protected Map |
pageSetterBeansMap
The list of page injectable Spring beans, keyed on page class name. |
static String |
SPRING_PATH
The Servlet initialization parameter name for the path to the Spring XML appliation context definition file: "spring-path". |
Fields inherited from class net.sf.click.ClickServlet |
CLICK_FORWARD, CONFIG_SERVICE_CLASS, configService, FORWARD_PAGE, logger, typeConverter |
Constructor Summary | |
SpringClickServlet()
|
Method Summary | |
protected void |
activatePageInstance(Page page)
This method associates the ApplicationContext with any ApplicationContextAware pages and supports the deserialized of stateful pages. |
protected ApplicationContext |
getApplicationContext()
Return the configured Spring application context. |
void |
init()
Initialize the SpringClickServlet and the Spring application context bean factory. |
protected Page |
newPageInstance(String path,
Class pageClass,
HttpServletRequest request)
Create a new Spring Page bean if defined in the application context, or a new Page instance otherwise. |
protected String |
toBeanName(Class aClass)
Return the Spring beanName for the given class. |
Methods inherited from class net.sf.click.ClickServlet |
createContext, createControlRegistry, createErrorPage, createPage, createPage, createPage, createPageImports, createTemplateModel, destroy, doGet, doPost, getConfigService, getTypeConverter, handleException, handleRequest, initPage, processPage, processPageOnDestroy, processPageRequestParams, renderJSP, renderTemplate, setPageResponseHeaders, setRequestAttributes |
Methods inherited from class javax.servlet.http.HttpServlet |
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service |
Methods inherited from class javax.servlet.GenericServlet |
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String INJECT_PAGE_BEANS
public static final String SPRING_PATH
protected ApplicationContext applicationContext
protected Map pageSetterBeansMap
Constructor Detail |
public SpringClickServlet()
Method Detail |
public void init() throws ServletException
ServletException
- if the click app could not be initializedClickServlet.init()
protected Page newPageInstance(String path, Class pageClass, HttpServletRequest request) throws Exception
path
- the request page pathpageClass
- the page Class the request is mapped torequest
- the page request
Exception
- if an error occurs creating the PageClickServlet.newPageInstance(String, Class, HttpServletRequest)
protected ApplicationContext getApplicationContext()
protected void activatePageInstance(Page page)
page
- the page instance to activateClickServlet.activatePageInstance(Page)
protected String toBeanName(Class aClass)
aClass
- the class to get the Spring bean name from
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |