Hitachi Vantara Pentaho Community Forums
Results 1 to 2 of 2

Thread: Problems with Multiple report and servlets

  1. #1
    Join Date
    Jun 2006
    Posts
    2

    Default Problems with Multiple report and servlets

    hi,

    i'm using multiple report to join two tableModel, and also use Servlet to generate and save the report in pdf format.
    when i use :
    worker = new DefaultPageableReportServletWorker(null,in,new PlDataModel());
    i enter in the PlDataModel constructor,
    but in the moment of worker.getReport, i don't know why i don't pass over the method getModel in the same class.

    i've other dataModel classes and everything was well.

    I hope i've explained my problem correctly, in any case, here's my code

    the method doPost of my servlet, the execution end at "catch Exception"

    Code:
    public void doPost(final HttpServletRequest request, final HttpServletResponse response)
          throws ServletException, IOException
      {
    	final URL in = getClass().getResource(ReportTemplates.getTemplateURL());
        if (in == null)
        {
          throw new ServletException("Missing Resource: "+ReportTemplates.getTemplateURL());
        }
        AbstractPageableReportServletWorker worker = null;
        switch (ReportConfig.getExportType()){
        case 1 : worker = new DefaultPageableReportServletWorker(null,in,new DataModel());
        		break;
        case 2 : worker = new DefaultPageableReportServletWorker(null,in,new ScDataModel());
    			break;
        case 3 : worker = new DefaultPageableReportServletWorker(null,in,new PlDataModel());
    			break; 	
        }      
        try
        {
          worker.getReport();
        }
        catch (NullPointerException e){
        	System.out.println("Null pointer exception,termino la ejecucion");
        	return;
        }
        catch (Exception e)
        {
          //response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
          System.out.println("Error found, execution end");
          return;
        }
    This is the PlDataModel Classe
    Code:
    import javax.swing.table.*;
    import org.jfree.report.ext.servletdemo.TableModelProvider;
    import org.jfree.report.modules.misc.tablemodel.JoiningTableModel;
    
    public class PlDataModel implements TableModelProvider{
    	private TableModel model;
    	
    	public PlDataModel(){
    		System.out.println("Entrando en la clasee PlDataModel");
    	}
    	
    	public TableModel getModel() {
    		Object[] columnNames;
    		TableModel windowModel;
    		TableModel elementModel;
    		int totalWindow = 0;
    		Planning pl = ReportData.getPlanning();
    		PlanningWindow[] windowList = pl.getPlanningWindowList();
    		
    		totalWindow += windowList.length;
    		
    		columnNames = new String[] { "windowID","windowOpen","windowClose" };
    		windowModel = new DefaultTableModel(columnNames, totalWindow);	
    		for &#40;int x = 0; x < totalWindow ; x++&#41; &#123;
    			windowModel.setValueAt&#40;windowList&#91;x&#93;.getEntityId&#40;&#41;,x,0&#41;;
    			windowModel.setValueAt&#40;windowList&#91;x&#93;.getHourOpenAsText&#40;&#41;,x,1&#41;;
    			windowModel.setValueAt&#40;windowList&#91;x&#93;.getHourClosedAsText&#40;&#41;,x,2&#41;;
    		&#125;
    		
    		int totalElement = 0;
    		PlanningElement&#91;&#93; elementList = pl.getPlanningElementList&#40;&#41;;
    		
    		totalElement += elementList.length;
    		
    		columnNames = new String&#91;&#93; &#123;"windowClose","elementID","elementName","elementState","elementComment","elementFirstEx","elementNextEx","elementInterval","elementExpire","elementTask" &#125;;
    		elementModel = new DefaultTableModel&#40;columnNames, totalElement &#41;;	
    		for &#40;int x = 0; x < totalElement; x++&#41; &#123;
    			elementModel.setValueAt&#40;elementList&#91;x&#93;.getEntityId&#40;&#41;,x,0&#41;;
    			elementModel.setValueAt&#40;elementList&#91;x&#93;.getTitle&#40;&#41;,x,1&#41;;
    			elementModel.setValueAt&#40;elementList&#91;x&#93;.getStatus&#40;&#41;,x,2&#41;;
    			elementModel.setValueAt&#40;elementList&#91;x&#93;.getComment&#40;&#41;,x,3&#41;;
    			elementModel.setValueAt&#40;elementList&#91;x&#93;.getFirstStartAsText&#40;&#41;,x,4&#41;;
    			elementModel.setValueAt&#40;elementList&#91;x&#93;.getNextExecutionAsText&#40;&#41;,x,5&#41;;
    			elementModel.setValueAt&#40;elementList&#91;x&#93;.getRescheduleInterval&#40;&#41;,x,6&#41;;
    			elementModel.setValueAt&#40;elementList&#91;x&#93;.getExpiryAsText&#40;&#41;,x,7&#41;;
    			//TODO&#58; Attencion, taskId puede ser cualquier classe			
    			try &#123;
    				String sc;
    				sc = ReportData.getTss&#40;&#41;.getScenarioEntity&#40;elementList&#91;x&#93;.getTaskId&#40;&#41;&#41;.getTitle&#40;&#41;;
    				elementModel.setValueAt&#40;sc,x,8&#41;;
    			&#125; catch &#40;TrackServerException e&#41; &#123;
    				e.printStackTrace&#40;&#41;;
    			&#125;	
    	   &#125;
    		
    		System.out.println&#40;"Classe PlDataModel&#58; Method getModel"&#41;;
    	    final JoiningTableModel jtm = new JoiningTableModel&#40;&#41;;
    	    jtm.addTableModel&#40;"window", windowModel&#41;;
    	    jtm.addTableModel&#40;"element", elementModel&#41;;
    	    return jtm;
    	&#125;
    		
    &#125;
    i've no idea what happens here :lol:

    somebody can help me? thanks in advance!

  2. #2
    Join Date
    Jun 2006
    Posts
    2

    Default fixed

    I'm fix the problem, it was in XML definition, no in java code...

    for the people who have the same problem with servlet, if you use AbstractPageableReportServletWorker class and his super AbstractReportServletWorker, when you use the method getReport in first time JFree take the report definition, and then get the DataModel for the report.

    So, if you have and exception make sure you have the report definition correctly defined, if it's ok,take a look to your DataModel constructor....

    bye,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.