Announcement Announcement Module
Collapse
No announcement yet.
Displaytag >> Table export as Excel issue Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Displaytag >> Table export as Excel issue

    I am using Spring Web Flow 2.x + Spring 2.5.4 on weblogic 9.2.

    I am using displaytag 1.1 for displaying a report. The table is propulating well in a pop up page( used spring popup) with a link at the bottom for Excel export. When I click on Export Excel, I am getting the following exception...

    I could understand what is the mistake I am doing. Appreciate some inputs.

    Code:
    Error 500--Internal Server Error
    
    org.springframework.webflow.execution.FlowExecutionException: Exception thrown in state 'providerListReportDisplay' of flow 'reports'
    	at org.springframework.webflow.engine.impl.FlowExecutionImpl.wrap(FlowExecutionImpl.java:568)
    	at org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:267)
    	at org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:153)
    	at org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:173)
    	at org.springframework.webflow.mvc.servlet.FlowController.handleRequest(FlowController.java:172)
    	at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
    	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    	at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    	at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    	at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
    	at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
    	at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
    	at org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:140)
    	at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
    	at org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:140)
    	at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
    	at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3242)
    	at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    	at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
    	at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2010)
    	at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1916)
    	at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1366)
    	at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
    	at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
    Caused by: java.lang.IllegalStateException: Exception occurred rendering view org.springframework.web.servlet.view.JstlView: name 'reports/providerListReport'; URL [/WEB-INF/jsp/reports/providerListReport.jsp]
    	at org.springframework.webflow.mvc.view.AbstractMvcView.render(AbstractMvcView.java:173)
    	at org.springframework.webflow.engine.ViewState.render(ViewState.java:257)
    	at org.springframework.webflow.engine.ViewState.resume(ViewState.java:216)
    	at org.springframework.webflow.engine.Flow.resume(Flow.java:551)
    	at org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:263)
    	... 27 more
    Caused by: java.lang.NullPointerException
    	at org.displaytag.export.ExportViewFactory.getView(ExportViewFactory.java:161)
    	at org.displaytag.tags.TableTag.doExport(TableTag.java:1347)
    	at org.displaytag.tags.TableTag.doEndTag(TableTag.java:1227)
    	at jsp_servlet._web_45_inf._jsp._reports.__providerlistreport._jspService(__providerlistreport.java:178)
    	at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
    	at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    	at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    	at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
    	at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
    	at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:530)
    	at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:266)
    	at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:240)
    	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:258)
    	at org.springframework.webflow.mvc.servlet.ServletMvcView.doRender(ServletMvcView.java:50)
    	at org.springframework.webflow.mvc.view.AbstractMvcView.render(AbstractMvcView.java:169)
    	... 31 more

    my flow XML is

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <flow xmlns="http://www.springframework.org/schema/webflow"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://www.springframework.org/schema/webflow
        http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
    
    	<on-start>
    		<evaluate
    			expression="mmsReportService.getMenuLayoutReportSelectionData()"
    			result="flowScope.menuLayoutReportSelectionData"
    			result-type="java.util.List">
    		</evaluate>
    		<evaluate
    			expression="mmsReportService.getCurrentListOfMenuPublishes()"
    			result="flowScope.currentListOfMenuPublishesData"
    			result-type="java.util.List">
    		</evaluate>
    
    
    	</on-start>
    
    	<view-state id="reportsHome" view="reports/mmsReports">
    
    		<transition on="ProviderListReport"
    			to="providerListReportDisplay">
    			<evaluate
    				expression="mmsReportService.getProviderListReport()"
    				result="flowScope.reportsHomeDisplay" result-type="java.util.List" />
    
    		</transition>
    	</view-state>
    	<view-state id="providerListReportDisplay"
    		view="reports/providerListReport" popup="true" redirect="true" >
    		<on-entry>
    			<render fragments="popup" />
    		</on-entry>
    		
    	</view-state>
    
    </flow>
    My web,xml is

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    	http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    
    	<servlet>
    		<servlet-name>mms</servlet-name>
    		<servlet-class>
    			org.springframework.web.servlet.DispatcherServlet
    		</servlet-class>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
    	<filter>
    		<filter-name>ResponseOverrideFilter</filter-name>
    		<filter-class>
    			org.displaytag.filter.ResponseOverrideFilter
    		</filter-class>
    	</filter>
    	
    	<filter-mapping>
    		<filter-name>ResponseOverrideFilter</filter-name>
    		<url-pattern>/reports.do</url-pattern>
    	</filter-mapping>
    
    		<servlet-name>mms</servlet-name>
    		<url-pattern>/dwr/*</url-pattern>
    	</servlet-mapping>
    	<servlet-mapping>
    		<servlet-name>mms</servlet-name>
    		<url-pattern>/support/*</url-pattern>
    	</servlet-mapping>
    	<servlet-mapping>
    		<servlet-name>mms</servlet-name>
    		<url-pattern>/menu/*</url-pattern>
    	</servlet-mapping>
    
    </web-app>

    my displaytag code in JSP is...

    Code:
    <display:table name="reportsHomeDisplay" cellspacing="0px"
    				cellpadding="0px" export="true" id="providerListReport"
    				requestURI="reports.do">
    				<display:column property="providerCode"></display:column>
    				<display:column property="providerText"></display:column>
    				<display:column property="delivery"></display:column>
    				<display:column property="providerNotes"></display:column>
    				<display:column property="excludeFromSearch"></display:column>
    				<display:column property="excludeFromWholeHouse"></display:column>
    				<display:column property="createdDate"></display:column>
    				<display:column property="createdBy"></display:column>
    			</display:table>

  • #2
    Hi

    I have done enough experimentation for a couple of days and found the efforts are not worth.

    I have moved on to JExcel and found it very easy and simple to use.

    Recommend JExcel to every one.

    Thanks

    Comment


    • #3
      Table Export as Excel Issue

      hi,
      Can you please tell me how to embedd jexcel with my spring appliaction.
      I also was not getting the data downloaded using the display tags.
      Please give me any sample code for it.

      Thanks in advance.

      Comment


      • #4
        Hi Pradeep

        Initially I have used Spring Web Flow 2.0 and then I used just Spring 2.5 MVC.

        I have used the Spring AbstractJExcelView class and overridden buildXXX(..,..,..,..) method.

        I will post the entire stuff soon for you.

        Thanks

        Comment


        • #5
          Displaytag &gt;&gt; Table export as Excel issue

          Hi Skadiy000,

          Thanks for reply.

          Actualy I am urgent requirement of doing it.
          Can you plz post the code as early as possible.
          And tell me the methods to override + how to proceed.

          In real I am getting data as an list from my DAO class.
          I want to export that list into excel.

          Just now I tried doing it with POI (Apache) but no luck.

          Thanks in advance.

          Comment


          • #6
            Hi Pradeep

            we have busy deliverable schedules and I could not find time to come back to this site. I hope the code snippets will help you. Regret for any delay from my side. good luck.

            Our Architect / Principal Engineer Madhav Deverkonda also contributed for this solution.

            Hereunder is the complete code:



            Controller:
            Code:
            public class ExcelController extends AbstractController {
            
            	protected Logger logger = Logger.getLogger(ExcelController.class);
            
            	protected MmsReportService reportService;
            
            	public ModelAndView handleRequestInternal(HttpServletRequest request,
            			HttpServletResponse response) throws Exception {
            
            		String requestURI = request.getRequestURI();
            
            		Map<String, Object> model = new HashMap<String, Object>();
            
            		try {
            
            			if (requestURI.indexOf("provList") != -1) {
            
            				List<ProviderListReport> providerListReportList = reportService
            						.getProviderListReportList();
            				model.put("providerListReportList", providerListReportList);
            				return new ModelAndView("providerListReportView", "model",
            						model);
            
            			}
            		} catch (Exception e) {
            			logger.error("Exception Occured", e);
            			throw e;
            		}
            
            		return null;
            	}
            
            	/**
            	 * @return the reportService
            	 */
            	public MmsReportService getReportService() {
            		return reportService;
            	}
            
            	/**
            	 * @param reportService
            	 *            the reportService to set
            	 */
            	public void setReportService(MmsReportService reportService) {
            		this.reportService = reportService;
            	}
            
            }
            Report Service:
            Code:
            public class MmsReportService {
            
            	/**
            	 * DAOs injected through spring configuration
            	 */
            	private CrudDao<ProviderListReport, String> providerListReportDao;
            	
            
            	private static Logger logger = Logger.getLogger(MmsReportService.class);
            
            	/*
            	 * Getter setters for the DAO instance injection
            	 */
            	public CrudDao<ProviderListReport, String> getProviderListReportDao() {
            		return this.providerListReportDao;
            	}
            
            	public void setProviderListReportDao(
            			CrudDao<ProviderListReport, String> providerListReportDao) {
            		this.providerListReportDao = providerListReportDao;
            	}
            
            	
            	/**
            	 * 
            	 * @param context
            	 * @throws IOException
            	 * @throws RowsExceededException
            	 * @throws WriteException
            	 * @throws DataAccessException
            	 */
            
            	public List<ProviderListReport> getProviderListReportList()
            			throws IOException, RowsExceededException, WriteException,
            			DataAccessException {
            
            		logger.debug("called getProviderListReportList()");
            		List<ProviderListReport> providerListReportList = providerListReportDao
            				.readAll();
            		logger.debug("Size of ProviderListReport List: "
            				+ providerListReportList.size());
            		return providerListReportList;
            	}
            
            }
            web.xml

            Code:
            <context-param>
            		<param-name>contextConfigLocation</param-name>
            		<param-value>
            			/WEB-INF/mms-servlet.xml
            		</param-value>
            	</context-param>
            <servlet>
            		<servlet-name>mms</servlet-name>
            		<servlet-class>
            			org.springframework.web.servlet.DispatcherServlet
            		</servlet-class>
            		<load-on-startup>1</load-on-startup>
            	</servlet>
            <servlet-mapping>
            		<servlet-name>mms</servlet-name>
            		<url-pattern>*.xls</url-pattern>
            	</servlet-mapping>
            View:

            Code:
            public class ProviderListReportView extends AbstractJExcelView {
            	private static Logger logger=Logger.getLogger(ProviderListReportView.class);
            	protected void buildExcelDocument(Map model,
                        WritableWorkbook workbook,
                        HttpServletRequest request,
                        HttpServletResponse response)
                    throws Exception {
                			
            		logger.debug("Building and Formating ProviderListData...");
            		List<ProviderListReport> providerListReportList = 
            			(List<ProviderListReport>)((Map)model.get("model")).get("providerListReportList");
            		
            		// If empty fill in empty object into the list
            		if (providerListReportList == null) {
            			providerListReportList = new ArrayList<ProviderListReport>();			
            		}
            
            		WritableSheet sheet = workbook.createSheet("Provider List Report", 0);
            		// Cell format for the title
            		WritableFont arial15Boldfont = new WritableFont(WritableFont.ARIAL, 15,
            				WritableFont.BOLD);
            		arial15Boldfont.setColour(Colour.GREEN);
            		WritableCellFormat arial15format = new WritableCellFormat(
            				arial15Boldfont);
            		arial15format.setAlignment(Alignment.CENTRE);
            
            		// Create a cell format for Arial 10 point font for header
            		WritableFont arial10Boldfont = new WritableFont(WritableFont.ARIAL, 10,
            				WritableFont.BOLD);
            		WritableCellFormat arial10format = new WritableCellFormat(
            				arial10Boldfont);
            		arial10format.setBackground(Colour.GREEN);
            		arial10Boldfont.setColour(Colour.WHITE);
            		arial10format.setAlignment(Alignment.CENTRE);
            		arial10format.setBorder(Border.ALL, BorderLineStyle.THIN);
            
            		// Create a cell format for Arial 8 point for data
            		WritableFont arial8font = new WritableFont(WritableFont.ARIAL, 8);
            		WritableCellFormat arial8format = new WritableCellFormat(arial8font);
            		arial8format.setAlignment(Alignment.LEFT);
            		arial8format.setVerticalAlignment(VerticalAlignment.TOP);
            		arial8format.setWrap(true);
            		sheet.setHeader("", "Provider List Report", "");
            		sheet.addCell(new Label(3, 1, "Provider List Report", arial15format));
            		sheet
            				.addCell(new Label(5, 1, "Report generated on: "
            						+ new java.util.Date(System.currentTimeMillis()),
            						arial8format));
            		int xx = 0;
            		int yy = 2;
            		// Created the Header for the data
            		sheet.addCell(new Label(xx, yy, "Provider Code", arial10format));
            		sheet.setColumnView(xx, "Provider Code".length() + 3);
            
            		sheet.addCell(new Label(xx + 1, yy, "Provider Name", arial10format));
            		sheet.setColumnView(xx + 1, "Provider Name".length() + 3);
            
            		sheet.addCell(new Label(xx + 2, yy, "Delivery", arial10format));
            		sheet.setColumnView(xx + 2, "Delivery".length() + 3);
            
            		sheet.addCell(new Label(xx + 3, yy, "Provider Notes", arial10format));
            		sheet.setColumnView(xx + 3, "Provider Notes".length() + 3);
            
            		sheet.addCell(new Label(xx + 4, yy, "Exclude From Search",
            				arial10format));
            		sheet.setColumnView(xx + 4, "Exclude From Search".length() + 3);
            
            		sheet.addCell(new Label(xx + 5, yy, "Exclude From Whole House",
            				arial10format));
            		sheet.setColumnView(xx + 5, "Exclude From Whole House".length() + 3);
            
            		sheet.addCell(new Label(xx + 6, yy, "Created Date", arial10format));
            		sheet.setColumnView(xx + 6, "Created Date".length() + 3);
            
            		sheet.addCell(new Label(xx + 7, yy, "Created By", arial10format));
            		sheet.setColumnView(xx + 7, "Created By".length() + 3);
            
            		sheet.addCell(new Label(xx + 8, yy, "Call Letter", arial10format));
            		sheet.setColumnView(xx + 8, "Call Letter".length() + 3);
            		
            		sheet.addCell(new Label(xx + 9, yy, "Domain Name", arial10format));
            		sheet.setColumnView(xx + 9, "Domain Name".length() + 3);
            
            		sheet.addCell(new Label(0, 1, "Total records: "
            				+ providerListReportList.size(), arial8format));
            		Iterator<ProviderListReport> it = (providerListReportList).iterator();
            		int x = 0;
            		int y = 3;
            		while (it.hasNext()) {
            			ProviderListReport plrModel = it.next();			
            			Number n1 = new Number(x, y, Double.parseDouble(plrModel
            					.getProviderCode()), arial8format);
            			sheet.addCell(n1);
            			if (n1.getContents().length() > "Provider Code".length() + 3)
            				sheet.setColumnView(x, (n1.getContents().length() + 3));
            
            			Label lable2 = new Label(x + 1, y, plrModel.getProviderName(),
            					arial8format);
            			sheet.addCell(lable2);
            			if (lable2.getContents().length() > "Provider Name".length() + 3)
            				sheet.setColumnView(x + 1, (lable2.getContents().length() + 3));
            
            			Label lable3 = new Label(x + 2, y, plrModel.getDelivery(),
            					arial8format);
            			sheet.addCell(lable3);
            			if (lable3.getContents().length() > "Delivery".length() + 3)
            				sheet.setColumnView(x + 2, (lable3.getContents().length() + 3));
            
            			Label lable4 = new Label(x + 3, y, plrModel.getProviderNotes(),
            					arial8format);
            			sheet.addCell(lable4);
            			if (lable4.getContents().length() > "Provider Notes".length() + 3)
            				sheet.setColumnView(x + 3, (lable4.getContents().length() + 5));
            
            			Label lable5 = new Label(x + 4, y, plrModel.getExcludeFromSearch(),
            					arial8format);
            			sheet.addCell(lable5);
            			if (lable5.getContents().length() > "Exclude From Search".length() + 3)
            				sheet.setColumnView(x + 4, (lable5.getContents().length() + 3));
            
            			Label lable6 = new Label(x + 5, y, plrModel
            					.getExcludeFromWholeHouse(), arial8format);
            			sheet.addCell(lable6);
            			if (lable6.getContents().length() > "Exclude From Whole House"
            					.length() + 3)
            				sheet.setColumnView(x + 5, (lable6.getContents().length() + 3));
            
            			Label lable7 = new Label(x + 6, y, plrModel.getCreatedDate()
            					.toString(), arial8format);
            			sheet.addCell(lable7);
            			if (lable7.getContents().length() > "Created Date".length() + 3)
            				sheet.setColumnView(x + 6, (lable7.getContents().length() + 3));
            
            			Label lable8 = new Label(x + 7, y, plrModel.getCreatedBy(),
            					arial8format);
            			sheet.addCell(lable8);
            			if (lable8.getContents().length() > "Created By".length() + 3)
            				sheet.setColumnView(x + 7, (lable8.getContents().length() + 3));
            
            			Label lable9 = new Label(x + 8, y, plrModel.getCallLetter(),
            					arial8format);
            			sheet.addCell(lable9);
            			if (lable9.getContents().length() > "Call Letter".length() + 3)
            				sheet.setColumnView(x + 8, (lable9.getContents().length() + 3));
            			
            			Label lable10 = new Label(x + 9, y, plrModel.getDomainName(),
            					arial8format);
            			sheet.addCell(lable10);
            			if (lable10.getContents().length() > "Domain Name".length() + 3)
            				sheet.setColumnView(x + 9, (lable10.getContents().length() + 3));
            
            			y++;
            		}
            	}
            }

            Comment


            • #7
              Table Export as Excel Issue

              Hi Skadiy000,

              Thanks a ton for posting the code.

              Its is realy very helpful

              but tell you ...
              I made the code for my application some 2 days back.....

              but that is specific to my application in the sense that it creates
              the columns in excel statically but now my requirement is to genaralise it .

              So that it should take the List as argument and should create column dynamically.

              Then converting the data to the excel sheet.

              Hope I wil be able to do it ...

              Thanks a lot again my frnd.

              Comment

              Working...
              X