Class JasperDesign
- All Implemented Interfaces:
Serializable,JRChangeEventsSupport,JRDefaultStyleProvider,JRIdentifiable,JRPropertiesHolder,JRReport
The class contains all report properties and report elements inherited from the
JRReport interface
in their design time state.
All its instances are subject to compilation before being used for filling and report generation. These instances are the raw material that the JasperReports library uses to generate reports. Such instances are usually obtained:
- by parsing the JRXML report template files using the library's internal XML-parsing utility classes.
- by applications that use JasperReports through API calls if working with JRXML files is not an option.
The first option for creating report designs relies on editing the JRXML files and using them
with the JasperCompileManager in order to prepare them
for filling with data. Because they are well structured and are validated against a public
XSD when parsed, these files can be easily edited using simple editors or specialized
XML editors.
The second option is recommended only in case the parent application that uses JasperReports inside the reporting module needs to create report templates at runtime. In most cases this is not needed because the report templates do not need to change with every report execution, and hence static report templates could be used. Only the data used to fill these static report templates is dynamic.
However, there are cases when the actual report template is the result of some user input. The parent application might supply its users with a set of options when launching the reports that might take the form of some simplified report designer or wizard. In such cases, the actual report layout is not known or is not complete at design time, and can only be put together after the user's input is received.
The most common use case scenario that requires dynamically built or ad hoc report templates (as we call them) is one in which the columns that are going to be present in a table-like report layout are not known at design time. Instead, the user will give the number of columns and their order inside the desired report at runtime.
Developers have to make sure that the applications they create really need ad hoc reports and cannot rely solely on static report templates. Since dynamically built report templates have to be compiled on the fly at runtime, they can result in a certain loss of performance.
- Author:
- Teodor Danciu (teodord@users.sourceforge.net)
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringFields inherited from class net.sf.jasperreports.engine.base.JRBaseReport
background, bottomMargin, columnCount, columnDirection, columnFooter, columnHeader, columnSpacing, columnWidth, datasets, defaultStyle, detailSection, formatFactoryClass, ignorePagination, importsSet, isFloatColumnFooter, isSummaryNewPage, isSummaryWithPageHeaderAndFooter, isTitleNewPage, language, lastPageFooter, leftMargin, mainDataset, name, noData, orientation, pageFooter, pageHeader, pageHeight, pageWidth, printOrder, PROPERTY_SECTION_TYPE, PROPERTY_WHEN_NO_DATA_TYPE, rightMargin, sectionType, styleResolver, styles, summary, templates, title, topMargin, whenNoDataTypeFields inherited from interface net.sf.jasperreports.engine.JRReport
CONFIG_PROPERTY_WHEN_NO_DATA_TYPE, LANGUAGE_GROOVY, LANGUAGE_JAVA -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a JasperDesign object and fills it with the default variables and parameters.JasperDesign(JasperReportsContext context) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDataset(int index, JRDesignDataset dataset) Inserts a sub dataset at specified position into the report.voidaddDataset(JRDesignDataset dataset) Adds a sub dataset to the report.voidvoidaddGroup(JRDesignGroup group) Gets a map of report groups.voidAdds an import (needed if report expression require additional classes in order to compile).voidaddParameter(JRParameter parameter) Adds a report parameter.voidaddPropertyExpression(DatasetPropertyExpression propertyExpression) voidaddScriptlet(JRScriptlet scriptlet) Adds a report scriplet.voidaddSortField(JRSortField sortField) voidInserts a report style, that can be referenced by report elements, at specified position.voidAdds a report style, that can be referenced by report elements.voidaddTemplate(int index, JRReportTemplate template) Inserts a report template at specified position.voidaddTemplate(JRReportTemplate template) Adds a report template.voidaddVariable(JRDesignVariable variable) protected List<JRCrosstab> Returns the sub datasets of the report indexed by name.Returns the datasets of this report.Returns the list of report sub datasets.Returns a collection of all report expressions.Gets a list of report fields.Gets a map of report fields.Returns the main dataset filter expression.Gets an array of report groups.Gets a list of report groups.Returns the main report dataset.Gets a list of report parameters (including built-in ones).Gets a map of report parameters (including built-in ones).Gets a list of report scriptlets (excluding the one specified by scriptletClass).Gets a map of report scriptlets (excluding the one specified by scriptletClass).Gets a list of sort report fields.JRStyle[]Gets an array of report level styles.Gets a list of report level styles.Returns the list of report templates.Returns the list of report templates defined in the report.static JasperDesignGets a list of report variables.Gets a map of report variables.booleanhasUUID()Determines whether the report has an existing unique identifier.voidPerforms preliminary processing and calculations prior to compilation.removeDataset(String datasetName) Removes a sub dataset from the report.removeDataset(JRDataset dataset) Removes a sub dataset from the report.removeField(String fieldName) removeField(JRField field) removeGroup(String groupName) Removes a new group from the report design.removeGroup(JRGroup group) voidremoveImport(String value) Removes an import.removeParameter(String parameterName) Removes a report parameter, based on its name.removeParameter(JRParameter parameter) Removes a report parameter.voidremovePropertyExpression(DatasetPropertyExpression propertyExpression) removeScriptlet(String scriptletName) Removes a report scriptlet, based on its name.removeScriptlet(JRScriptlet scriptlet) Removes a report scriptlet.removeSortField(JRSortField sortField) removeStyle(String styleName) Removes a report style from the list, based on the style name.removeStyle(JRStyle style) Removes a report style from the list.booleanremoveTemplate(JRReportTemplate template) Removes a report template.static voidstatic voidremoveVariable(String variableName) removeVariable(JRVariable variable) voidvoidsetBackground(JRBand background) Sets the background band.protected voidsetBandOrigin(JRBand band, BandTypeEnum type) voidsetBottomMargin(int bottomMargin) Sets the top margin.voidsetColumnCount(Integer columnCount) Specifies the number of report columns.voidsetColumnDirection(RunDirectionEnum columnDirection) Sets the column direction.voidsetColumnFooter(JRBand columnFooter) Sets the column footer band.voidsetColumnHeader(JRBand columnHeader) Sets the column header band.voidsetColumnSpacing(int columnSpacing) Sets the spacing between columns.voidsetColumnWidth(int columnWidth) Sets the column width.voidsetDefaultStyle(JRStyle style) voidsetFilterExpression(JRExpression expression) Sets the main dataset filter expression.voidsetFloatColumnFooter(boolean isFloatColumnFooter) Flag used to specify if the column footer section should be printed at the bottom of the column or if it should immediately follow the last detail or group footer printed on the current column.voidsetFormatFactoryClass(String formatFactoryClass) voidsetIgnorePagination(boolean ignorePagination) Sets the value of the ignore pagination flag.voidsetLanguage(String language) Specifies the language used for report expressions (Java or Groovy).voidsetLastPageFooter(JRBand lastPageFooter) Sets the last page footer band.voidsetLeftMargin(int leftMargin) Sets the left margin.voidsetMainDataset(JRDesignDataset dataset) Sets the main report dataset.voidSets the report name.voidSets the noData band.voidsetOrientation(OrientationEnum orientation) Sets the report orientation.voidsetPageFooter(JRBand pageFooter) Sets the page footer band.voidsetPageHeader(JRBand pageHeader) Sets the page header band.voidsetPageHeight(int pageHeight) Sets page height (including margins etc.).voidsetPageWidth(int pageWidth) Sets page width (including margins etc.).voidsetPrintOrder(PrintOrderEnum printOrder) Sets the print order.voidsetQuery(JRDesignQuery query) Specifies the report query.voidsetResourceBundle(String resourceBundle) Sets the base name of the report associated resource bundle.voidsetRightMargin(int rightMargin) Sets the right margin.voidsetScriptletClass(String scriptletClass) protected voidsetSectionOrigin(JRSection section, BandTypeEnum type) voidsetSummary(JRBand summary) Sets the summary band.voidsetSummaryNewPage(boolean isSummaryNewPage) Flag used to specify if the summary section should be printed on a separate last page.voidsetSummaryWithPageHeaderAndFooter(boolean isSummaryWithPageHeaderAndFooter) Flag used to specify if the summary section should be accompanied by the page header and footer.static voidsetThreadJasperReportsContext(JasperReportsContext jasperReportsContext) voidSets the title band.voidsetTitleNewPage(boolean isTitleNewPage) Flag used to specify if the title section should be printed on a separate initial page.voidsetTopMargin(int topMargin) Sets the top margin.voidSets the unique identifier for the report.Methods inherited from class net.sf.jasperreports.engine.base.JRBaseReport
copyTemplates, getAllBands, getBackground, getBottomMargin, getColumnCount, getColumnDirection, getColumnFooter, getColumnHeader, getColumnSpacing, getColumnWidth, getDefaultStyle, getDetailSection, getEventSupport, getFields, getFormatFactoryClass, getGroups, getImports, getLanguage, getLastPageFooter, getLeftMargin, getMainDataset, getName, getNoData, getOrientation, getPageFooter, getPageHeader, getPageHeight, getPageWidth, getParameters, getParentProperties, getPrintOrder, getPropertiesMap, getProperty, getPropertyExpressions, getPropertyNames, getQuery, getResourceBundle, getRightMargin, getScriptletClass, getScriptlets, getSectionType, getSortFields, getStyleResolver, getSummary, getTitle, getTopMargin, getUUID, getVariables, getWhenNoDataType, getWhenResourceMissingType, hasProperties, isFloatColumnFooter, isIgnorePagination, isSummaryNewPage, isSummaryWithPageHeaderAndFooter, isTitleNewPage, removeProperty, setJasperReportsContext, setProperty, setSectionType, setWhenNoDataType, setWhenResourceMissingType
-
Field Details
-
EXCEPTION_MESSAGE_KEY_DUPLICATE_DATASET
- See Also:
-
EXCEPTION_MESSAGE_KEY_DUPLICATE_REPORT_STYLE
- See Also:
-
PROPERTY_BACKGROUND
- See Also:
-
PROPERTY_BOTTOM_MARGIN
- See Also:
-
PROPERTY_COLUMN_COUNT
- See Also:
-
PROPERTY_COLUMN_FOOTER
- See Also:
-
PROPERTY_COLUMN_HEADER
- See Also:
-
PROPERTY_COLUMN_SPACING
- See Also:
-
PROPERTY_COLUMN_WIDTH
- See Also:
-
PROPERTY_DATASETS
- See Also:
-
PROPERTY_DEFAULT_FONT
- See Also:
-
PROPERTY_DEFAULT_STLYE
- See Also:
-
PROPERTY_DETAIL
- See Also:
-
PROPERTY_FLOAT_COLUMN_FOOTER
- See Also:
-
PROPERTY_FONTS
- See Also:
-
PROPERTY_FORMAT_FACTORY_CLASS
- See Also:
-
PROPERTY_IGNORE_PAGINATION
- See Also:
-
PROPERTY_IMPORTS
- See Also:
-
PROPERTY_LANGUAGE
- See Also:
-
PROPERTY_LAST_PAGE_FOOTER
- See Also:
-
PROPERTY_LEFT_MARGIN
- See Also:
-
PROPERTY_MAIN_DATASET
- See Also:
-
PROPERTY_NAME
- See Also:
-
PROPERTY_NO_DATA
- See Also:
-
PROPERTY_ORIENTATION
- See Also:
-
PROPERTY_PAGE_FOOTER
- See Also:
-
PROPERTY_PAGE_HEADER
- See Also:
-
PROPERTY_PAGE_HEIGHT
- See Also:
-
PROPERTY_PAGE_WIDTH
- See Also:
-
PROPERTY_PRINT_ORDER
- See Also:
-
PROPERTY_COLUMN_DIRECTION
- See Also:
-
PROPERTY_RIGHT_MARGIN
- See Also:
-
PROPERTY_STYLES
- See Also:
-
PROPERTY_SUMMARY
- See Also:
-
PROPERTY_SUMMARY_NEW_PAGE
- See Also:
-
PROPERTY_SUMMARY_WITH_PAGE_HEADER_AND_FOOTER
- See Also:
-
PROPERTY_TEMPLATES
- See Also:
-
PROPERTY_TITLE
- See Also:
-
PROPERTY_TITLE_NEW_PAGE
- See Also:
-
PROPERTY_TOP_MARGIN
- See Also:
-
-
Constructor Details
-
JasperDesign
public JasperDesign()Constructs a JasperDesign object and fills it with the default variables and parameters. -
JasperDesign
-
-
Method Details
-
setThreadJasperReportsContext
-
removeThreadJasperReportsContext
public static void removeThreadJasperReportsContext() -
getThreadInstance
-
removeThreadInstance
public static void removeThreadInstance() -
setName
Sets the report name. It is strongly recommended that the report name matches the .jrxml file name, since report compilers usually use this name for the compiled .jasper file. -
setLanguage
Specifies the language used for report expressions (Java or Groovy). The default is Java. -
setColumnCount
Specifies the number of report columns. -
setPrintOrder
Sets the print order. In case of multiple column reports, the engine can perform vertical or horizontal fill.- See Also:
-
setColumnDirection
Sets the column direction. -
setPageWidth
public void setPageWidth(int pageWidth) Sets page width (including margins etc.). Default is 595. -
setPageHeight
public void setPageHeight(int pageHeight) Sets page height (including margins etc.). Default is 842. -
setOrientation
Sets the report orientation.- See Also:
-
setColumnWidth
public void setColumnWidth(int columnWidth) Sets the column width. -
setColumnSpacing
public void setColumnSpacing(int columnSpacing) Sets the spacing between columns. -
setLeftMargin
public void setLeftMargin(int leftMargin) Sets the left margin. The working space is calculated by subtracting the margins from the page width. -
setRightMargin
public void setRightMargin(int rightMargin) Sets the right margin. The working space is calculated by subtracting the margins from the page width. -
setTopMargin
public void setTopMargin(int topMargin) Sets the top margin. The working space is calculated by subtracting the margins from the page height. -
setBottomMargin
public void setBottomMargin(int bottomMargin) Sets the top margin. The working space is calculated by subtracting the margins from the page height. -
setBackground
Sets the background band. -
setTitle
Sets the title band. -
setTitleNewPage
public void setTitleNewPage(boolean isTitleNewPage) Flag used to specify if the title section should be printed on a separate initial page.- Parameters:
isTitleNewPage- true if the title section should be displayed on a separate initial page, false if it will be displayed on the first page along with other sections.
-
setSummary
Sets the summary band. -
setNoData
Sets the noData band. -
setSummaryNewPage
public void setSummaryNewPage(boolean isSummaryNewPage) Flag used to specify if the summary section should be printed on a separate last page.- Parameters:
isSummaryNewPage- true if the summary section should be displayed on a separate last page, false if it will be displayed on the last page along with other sections, if there is enough space.
-
setPageHeader
Sets the page header band. -
setColumnHeader
Sets the column header band. -
setScriptletClass
-
setFormatFactoryClass
-
setResourceBundle
Sets the base name of the report associated resource bundle. -
addImport
Adds an import (needed if report expression require additional classes in order to compile). -
removeImport
Removes an import. -
resetDefaultStyle
public void resetDefaultStyle() -
setDefaultStyle
-
getStyles
Gets an array of report level styles. These styles can be referenced by report elements.- Specified by:
getStylesin interfaceJRReport- Overrides:
getStylesin classJRBaseReport
-
getStylesList
Gets a list of report level styles. These styles can be referenced by report elements. -
getStylesMap
-
addStyle
Adds a report style, that can be referenced by report elements.- Throws:
JRException
-
addStyle
Inserts a report style, that can be referenced by report elements, at specified position.- Throws:
JRException
-
removeStyle
Removes a report style from the list, based on the style name. -
removeStyle
Removes a report style from the list. -
getScriptletsList
Gets a list of report scriptlets (excluding the one specified by scriptletClass). -
getScriptletsMap
Gets a map of report scriptlets (excluding the one specified by scriptletClass). -
addScriptlet
Adds a report scriplet.- Throws:
JRException
-
removeScriptlet
Removes a report scriptlet, based on its name. -
addPropertyExpression
-
removePropertyExpression
-
removePropertyExpression
-
getPropertyExpressionsList
-
removeScriptlet
Removes a report scriptlet. -
getParametersList
Gets a list of report parameters (including built-in ones). -
getParametersMap
Gets a map of report parameters (including built-in ones). -
addParameter
Adds a report parameter.- Throws:
JRException
-
removeParameter
Removes a report parameter, based on its name. -
removeParameter
Removes a report parameter. -
setQuery
Specifies the report query. -
getFieldsList
Gets a list of report fields. -
getFieldsMap
Gets a map of report fields. -
addField
- Throws:
JRException
-
removeField
-
removeField
-
getSortFieldsList
Gets a list of sort report fields. -
addSortField
- Throws:
JRException
-
removeSortField
-
getVariablesList
Gets a list of report variables. -
getVariablesMap
Gets a map of report variables. -
addVariable
- Throws:
JRException
-
removeVariable
-
removeVariable
-
getGroupsList
Gets an array of report groups. -
getGroupsMap
Gets a list of report groups. -
addGroup
Gets a map of report groups.- Throws:
JRException
-
removeGroup
Removes a new group from the report design. -
removeGroup
-
getExpressions
Returns a collection of all report expressions. -
getDatasets
Description copied from interface:JRReportReturns the datasets of this report.- Specified by:
getDatasetsin interfaceJRReport- Overrides:
getDatasetsin classJRBaseReport- Returns:
- the datasets of this report
-
getDatasetsList
Returns the list of report sub datasets.- Returns:
- list of
JRDesignDatasetobjects
-
getDatasetMap
Returns the sub datasets of the report indexed by name.- Returns:
- the sub datasets of the report indexed by name
-
addDataset
Adds a sub dataset to the report.- Parameters:
dataset- the dataset- Throws:
JRException
-
addDataset
Inserts a sub dataset at specified position into the report.- Parameters:
index- the positiondataset- the dataset- Throws:
JRException
-
removeDataset
Removes a sub dataset from the report.- Parameters:
datasetName- the dataset name- Returns:
- the removed dataset
-
removeDataset
Removes a sub dataset from the report.- Parameters:
dataset- the dataset to be removed- Returns:
- the dataset
-
getMainDesignDataset
Returns the main report dataset.- Returns:
- the main report dataset
-
setMainDataset
Sets the main report dataset.This method can be used as an alternative to setting the parameters, fields, etc directly on the report.
- Parameters:
dataset- the dataset
-
preprocess
public void preprocess()Performs preliminary processing and calculations prior to compilation. -
getCrosstabs
-
setIgnorePagination
public void setIgnorePagination(boolean ignorePagination) Sets the value of the ignore pagination flag.- Parameters:
ignorePagination- whether to ignore pagination when generating the report- See Also:
-
getFilterExpression
Returns the main dataset filter expression.- Returns:
- the main dataset filter expression
- See Also:
-
setFilterExpression
Sets the main dataset filter expression.- Parameters:
expression- the boolean expression to use as main dataset filter expression- See Also:
-
addTemplate
Adds a report template.- Parameters:
template- the template to add.- See Also:
-
addTemplate
Inserts a report template at specified position.- Parameters:
index- the template position.template- the template to insert.- See Also:
-
removeTemplate
Removes a report template.- Parameters:
template- the template to remove- Returns:
trueif and only if the template has been found and removed
-
getTemplates
Description copied from interface:JRReportReturns the list of report templates. A report template is an expression which resolves at runtime to atemplate. Templates include styles which can be used in the report. The order in which the templates are included in the report is important:- A style's parent must appear before the style itself.
- A style overrides styles with the same name that are placed before it. Also, report styles override templates styles with the same name.
- Specified by:
getTemplatesin interfaceJRReport- Overrides:
getTemplatesin classJRBaseReport- Returns:
- the list of report templates, or
nullif none - See Also:
-
getTemplatesList
Returns the list of report templates defined in the report.- Returns:
- the list of
JRReportTemplateobjects for the report - See Also:
-
setBandOrigin
-
setSectionOrigin
-
setUUID
Sets the unique identifier for the report.- Parameters:
uuid- the identifier
-
hasUUID
public boolean hasUUID()Determines whether the report has an existing unique identifier. Note that when no existing identifier is set,JRBaseReport.getUUID()would generate and return an identifier.- Returns:
- whether the report has an externally set unique identifier
- See Also:
-