Jump to content
Changes to the Jaspersoft community edition download ×

Problem with the ListComponent in the desing - fails to compile


sskotnicky

Recommended Posts

Hi. I am trying to create a desing containg a list of some texts, but anytime I try to compile the desing I get the "Exception occurred in target VM: Error compiling report design.<" error.

Can anyone look at my code and let me  know what I have wrong? Thanks a lot.

 

JasperDesign design = new JasperDesign();
design.setName("design");

//creates a description field and add it to desing
JRDesignField descriptionsField = new JRDesignField();
descriptionsField.setName("descriptions");
descriptionsField.setValueClass(net.sf.jasperreports.engine.data.JRBeanCollectionDataSource.class);
design.addField(descriptionsField);

//creates a dataset
JRDesignDataset descriptionsDataSet = new JRDesignDataset(false);
descriptionsDataSet.setName("descriptionsDS");

//creates a field in the dataset
JRDesignField text = new JRDesignField();
text.setName("descText");
descriptionsDataSet.addField(text);

//adds dataset into desing
design.addDataset(descriptionsDataSet);

ListComponent listComponent = new ListComponent() {
    @Override
    public JRDatasetRun getDatasetRun() {
        JRDesignDatasetRun datasetRun = new JRDesignDatasetRun();
        datasetRun.setDatasetName("descriptionsDS");
        datasetRun.setDataSourceExpression(new JRDesignExpression("$F{descriptions}"));
        return datasetRun;
    }

    @Override
    public ListContents getContents() {
        DesignListContents listContents = new DesignListContents();
        JRDesignTextField text = new JRDesignTextField();
        text.setExpression(new JRDesignExpression("$F{descText}"));
        text.setWidth(555);
        text.setHeight(20);
        text.setX(0);
        text.setY(0);
        text.setPrintWhenDetailOverflows(true);
        text.setPositionType(PositionTypeEnum.FLOAT);
        text.setStretchType(StretchTypeEnum.ELEMENT_GROUP_HEIGHT);
        text.setStretchWithOverflow(true);
        listContents.addElement(text);
        listContents.setWidth(555);
        listContents.setHeight(20);
        return listContents;
    }

    @Override
    public PrintOrderEnum getPrintOrderValue() {
        return PrintOrderEnum.VERTICAL;
    }

    @Override
    public Boolean getIgnoreWidth() {
        //does nothing because this flag only applies to horizontally filled reports
        return Boolean.FALSE;
    }

    @Override
    public void visit(JRVisitor jrv) {
        //ignored
    }

    @Override
    public Object clone() {
        try {
            return super.clone();
        } catch (CloneNotSupportedException ex) {
            java.util.logging.Logger.getLogger(PrintServer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        return null;
    }
};

JRDesignComponentElement componentElement = new JRDesignComponentElement();
componentElement.setPositionType(PositionTypeEnum.FLOAT);
componentElement.setStretchType(StretchTypeEnum.ELEMENT_GROUP_HEIGHT);
componentElement.setWidth(555);
componentElement.setHeight(20);

componentElement.setComponent(listComponent);
componentElement.setComponentKey(new ComponentKey("http://jasperreports.sourceforge.net/jasperreports/components", "jr", "list" ));
JRDesignBand descBand = new JRDesignBand();
descBand.addElement(componentElement);
descBand.setSplitType(SplitTypeEnum.STRETCH);
descBand.setHeight(20);

JRDesignSection detailSection = (JRDesignSection) design.getDetailSection();
detailSection.addBand(descBand);

JasperCompileManager.compileReport(design);

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...