org.springframework.web.servlet.view.document
Class AbstractJExcelView

java.lang.Object
  extended by org.springframework.context.support.ApplicationObjectSupport
      extended by org.springframework.web.context.support.WebApplicationObjectSupport
          extended by org.springframework.web.servlet.view.AbstractView
              extended by org.springframework.web.servlet.view.document.AbstractJExcelView
All Implemented Interfaces:
BeanNameAware, ApplicationContextAware, ServletContextAware, View

public abstract class AbstractJExcelView
extends AbstractView

Convenient superclass for Excel document views.

This class uses the JExcelAPI instead of POI. More information on JExcelAPI can be found on their website.

Properties:

The file will be searched with locations in the following order:

For working with the workbook in the subclass, see Java Excel API site

As an example, you can try this snippet:

 protected void buildExcelDocument(
      Map<String, Object> model, WritableWorkbook workbook,
                HttpServletRequest request, HttpServletResponse response) {

         if (workbook.getNumberOfSheets() == 0) {
             workbook.createSheet("Spring", 0);
   }
 
         WritableSheet sheet = workbook.getSheet("Spring");
         Label label = new Label(0, 0, "This is a nice label");
         sheet.addCell(label);
 }
The use of this view is close to the AbstractExcelView class, just using the JExcel API instead of the Apache POI API.

Since:
1.2.5
Author:
Bram Smeets, Alef Arendsen, Juergen Hoeller
See Also:
AbstractExcelView, AbstractPdfView

Field Summary
 
Fields inherited from class org.springframework.web.servlet.view.AbstractView
DEFAULT_CONTENT_TYPE
 
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
logger
 
Fields inherited from interface org.springframework.web.servlet.View
RESPONSE_STATUS_ATTRIBUTE
 
Constructor Summary
AbstractJExcelView()
          Default Constructor.
 
Method Summary
protected abstract  void buildExcelDocument(Map<String,Object> model, jxl.write.WritableWorkbook workbook, HttpServletRequest request, HttpServletResponse response)
          Subclasses must implement this method to create an Excel Workbook document, given the model.
protected  boolean generatesDownloadContent()
          Return whether this view generates download content (typically binary content like PDF or Excel files).
protected  jxl.Workbook getTemplateSource(String url, HttpServletRequest request)
          Create the workbook from an existing XLS document.
protected  void renderMergedOutputModel(Map<String,Object> model, HttpServletRequest request, HttpServletResponse response)
          Renders the Excel view, given the specified model.
 void setUrl(String url)
          Set the URL of the Excel workbook source, without localization part nor extension.
 
Methods inherited from class org.springframework.web.servlet.view.AbstractView
addStaticAttribute, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getStaticAttributes, prepareResponse, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setRequestContextAttribute, toString, writeToResponse
 
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
 
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, requiredContextClass, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractJExcelView

public AbstractJExcelView()
Default Constructor. Sets the content type of the view to "application/vnd.ms-excel".

Method Detail

setUrl

public void setUrl(String url)
Set the URL of the Excel workbook source, without localization part nor extension.


generatesDownloadContent

protected boolean generatesDownloadContent()
Description copied from class: AbstractView
Return whether this view generates download content (typically binary content like PDF or Excel files).

The default implementation returns false. Subclasses are encouraged to return true here if they know that they are generating download content that requires temporary caching on the client side, typically via the response OutputStream.

Overrides:
generatesDownloadContent in class AbstractView
See Also:
AbstractView.prepareResponse(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse), ServletResponse.getOutputStream()

renderMergedOutputModel

protected final void renderMergedOutputModel(Map<String,Object> model,
                                             HttpServletRequest request,
                                             HttpServletResponse response)
                                      throws Exception
Renders the Excel view, given the specified model.

Specified by:
renderMergedOutputModel in class AbstractView
Parameters:
model - combined output Map (never null), with dynamic values taking precedence over static attributes
request - current HTTP request
response - current HTTP response
Throws:
Exception - if rendering failed

getTemplateSource

protected jxl.Workbook getTemplateSource(String url,
                                         HttpServletRequest request)
                                  throws Exception
Create the workbook from an existing XLS document.

Parameters:
url - the URL of the Excel template without localization part nor extension
request - current HTTP request
Returns:
the template workbook
Throws:
Exception - in case of failure

buildExcelDocument

protected abstract void buildExcelDocument(Map<String,Object> model,
                                           jxl.write.WritableWorkbook workbook,
                                           HttpServletRequest request,
                                           HttpServletResponse response)
                                    throws Exception
Subclasses must implement this method to create an Excel Workbook document, given the model.

Parameters:
model - the model Map
workbook - the Excel workbook to complete
request - in case we need locale etc. Shouldn't look at attributes.
response - in case we need to set cookies. Shouldn't write to it.
Throws:
Exception - in case of failure