|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface SpringIntegration
Overview
The Spring framework has many different parts, from integration with Object Relational Mapping (ORM) and transaction management systems, to a Model View Controller (MVC) architecture.
If you are building a new application from scratch and/or you are trying to
modernize the presentation layer of an existing application, most of Spring MVC is
inapplicable in the 'SmartGWT architecture'
. Specifically,
SmartGWT renders all HTML on the client, and the server is responsible only for
retrieving data and enforcing business rules. This means that Spring's ModelAndView and all
functionality related to retrieving and rendering Views is unnecessary in SmartGWT.
SmartGWT only needs the Model, and provides methods to deliver that Model to SmartGWT
components (the server side method DSResponse.setData()).
However, Spring's DispatchServlet, Handler chain, and Controller architecture is applicable to SmartGWT. See "Using Spring Controllers" below.
Existing Spring Application
As discussed under the general 'server integration'
topic, integrating SmartGWT into your application involves finding a way to provide data
that fulfills the DSRequest
sent by SmartGWT components.
There are 2 approaches for integrating SmartGWT into an existing Spring application:
RestDataSource
provides a
standard "REST" XML or JSON-based protocol you can implement, or you can adapt generic
DataSource
to existing formats.
In some Spring applications, all existing Spring workflows can be made callable by SmartGWT with a generic View class capable of serializing the Model to XML or JSON, combined with a Controller that always uses this View. Consider the following Java anonymous class, which uses the SmartGWT JSTranslater class to dump the entire Spring Model as a JSON response.
new View() { public void render(Map model, HttpServletRequest request, HttpServletResponse response) throws IOException { final ServletOutputStream outputStream = response.getOutputStream(); response.setContentType("application/x-javascript"); outputStream.println(JSTranslater.get().toJS(model)); outputStream.close(); } public String getContentType() { return "application/x-javascript"; } }
If you use this approach, you do not need to install the SmartGWT server, and can
'deploy'
SmartGWT as simple web content (JS/media/HTML files). If you
are already familiar with how to generate XML from objects that typically appear in your
Spring Models, this may be the easiest path.
DSRequest
to beans managed by Spring, via
lookupStyle
:"spring". Return data to the browser by either simply
returning it from your method, or via calling DSResponse.setData() (server-side method).
If, from a bean created by Spring, you can easily create the data you typically use to
populate a Model in a ModelAndView, this may be the easiest path.
Using Spring Controllers with SmartGWT DMI
You can create a Controller that invokes standard SmartGWT server request processing, including DMI, like so:
public class SmartGWTRPCController extends AbstractController { public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { // invoke SmartGWT server standard request processing com.isomorphic.rpc.RPCManager.processRequest(request, response); return null; // avoid default rendering } }This lets you use Spring's DispatchServlet, Handler chain and Controller architecture as a pre- and post-processing model wrapped around SmartGWT DMI.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |