Class JasperMultipleReportBaseAction
- java.lang.Object
-
- org.openxava.actions.BaseAction
-
- org.openxava.actions.ViewBaseAction
-
- org.openxava.actions.JasperMultipleReportBaseAction
-
- All Implemented Interfaces:
IAction,IChangeModeAction,IModelAction,IModuleContextAction,IMultipleForwardAction,IRequestAction
- Direct Known Subclasses:
JasperConcatReportBaseAction
public abstract class JasperMultipleReportBaseAction extends ViewBaseAction implements IMultipleForwardAction, IModelAction
To generate several custom Jasper Reports with the same action.You only need to overwrite the abstract methods.
To send parameters to the reports you have 3 options.- If all the repors use the same parameters just overwrite getParameters().
- If each report has different parameter overwrite getParameters(int i), or well
- overwrite execute() and before calling to super.execute() call to addParameters() method.
Option 1 for parameters
public Map getParameters() throws Exception { Map parameters = new HashMap(); parameters.put("param1", value1); parameters.put("param2", value2); return parameters; }Option 2 for parameters
protected Map getParameters(int index) throws Exception { Map parameters = new HashMap(); switch (index) { case 0: parameters.put("param1", value1); parameters.put("param2", value2); return parameters; case 1: parameters.put("param3", value3); parameters.put("param4", value4); return parameters; } return null; }Option 3 for parameters
public void execute() throws Exception { Map parameters1 = new HashMap(); parameters1.put("param1", value1); parameters1.put("param2", value2); addParameters(parameters1); Map parameters2 = new HashMap(); parameters1.put("param3", value3); parameters1.put("param4", value4); addParameters(parameters2); super.execute(); }- Author:
- Oscar Caro, Franklin Alier : Added a parameters list to allow separate parameters per report
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringEXCELstatic java.lang.StringODTstatic java.lang.StringPDFstatic java.lang.StringRTF-
Fields inherited from interface org.openxava.actions.IChangeModeAction
DETAIL, LIST, PREVIOUS_MODE, SPLIT
-
-
Constructor Summary
Constructors Constructor Description JasperMultipleReportBaseAction()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddParameters(int index, java.util.Map parameters)Add a parameter set at a specified index.voidaddParameters(java.util.Map parameters)Add a parameter set to the current list.voidexecute()protected abstract net.sf.jasperreports.engine.JRDataSource[]getDataSources()Data to print.java.lang.StringgetFormat()Output report format, it can be 'pdf' or 'excel'.java.lang.String[]getForwardURIs()The URIs to go.protected abstract java.lang.String[]getJRXMLs()The name of the XML with the JasperReports design.protected java.util.MapgetParameters()Parameters to send to report.protected java.util.MapgetParameters(int i)Retrieve parameters for the specified report index.java.util.List<java.util.Map>getParametersList()Retrieve the current parameter list.booleaninNewWindow()voidsetFormat(java.lang.String format)Output report format, it can be 'pdf', 'excel' or 'rtf'.voidsetModel(java.lang.String modelName)voidsetParametersList(java.util.List<java.util.Map> parametersList)Set parameter list.-
Methods inherited from class org.openxava.actions.ViewBaseAction
changeThisPropertyByViewValue, closeDialog, getModelName, getPreviousView, getPreviousViews, getView, resetDescriptionsCache, returnToPreviousView, setControllers, setPreviousViews, setView, showDialog, showDialog, showNewView, showView, validateViewValues
-
Methods inherited from class org.openxava.actions.BaseAction
addActions, addError, addErrors, addInfo, addMessage, addMessages, addWarning, clearActions, commit, executeAction, executeAfter, executeBefore, getContext, getEnvironment, getErrors, getLocale, getManager, getMessages, getNextMode, getQualifiedActionIfAvailable, getRequest, removeActions, returnToPreviousControllers, rollback, setContext, setDefaultControllers, setEnvironment, setErrors, setMessages, setNextMode, setRequest
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.openxava.actions.IAction
getErrors, getMessages, setEnvironment, setErrors, setMessages
-
-
-
-
Method Detail
-
getDataSources
protected abstract net.sf.jasperreports.engine.JRDataSource[] getDataSources() throws java.lang.ExceptionData to print.If return null then a JDBC connection is sent to JasperReport, this is for the case of a SQL inside JasperReport design.
- Throws:
java.lang.Exception
-
getJRXMLs
protected abstract java.lang.String[] getJRXMLs() throws java.lang.ExceptionThe name of the XML with the JasperReports design.If it is a relative path (as
reports/myreport.jrxmlhas to be in classpath. If it is a absolute path (as/home/java/reports/myreport.xmlorC:\\JAVA\\REPORTS\MYREPORT.JRXMLthen it look at the file system.- Throws:
java.lang.Exception
-
getParameters
protected java.util.Map getParameters() throws java.lang.ExceptionParameters to send to report.- Throws:
java.lang.Exception
-
getParameters
protected java.util.Map getParameters(int i) throws java.lang.ExceptionRetrieve parameters for the specified report index.Maintains backward compatibility by calling getParameters() if parameters list is empty or not enough parameter sets defined.
- Throws:
java.lang.Exception- Since:
- 4.5
-
getFormat
public java.lang.String getFormat() throws java.lang.ExceptionOutput report format, it can be 'pdf' or 'excel'.- Throws:
java.lang.Exception
-
setFormat
public void setFormat(java.lang.String format) throws java.lang.ExceptionOutput report format, it can be 'pdf', 'excel' or 'rtf'.- Throws:
java.lang.Exception
-
execute
public void execute() throws java.lang.Exception
-
getForwardURIs
public java.lang.String[] getForwardURIs()
Description copied from interface:IMultipleForwardActionThe URIs to go.If it starts with "http://" or "http://" the action will forward to the absolute URL in internet, if it starts with "javascript:" the corresponding code will executed by the browser, otherwise it will forward to a resource inside this application.
- Specified by:
getForwardURIsin interfaceIMultipleForwardAction
-
inNewWindow
public boolean inNewWindow()
-
setModel
public void setModel(java.lang.String modelName)
- Specified by:
setModelin interfaceIModelAction
-
setParametersList
public void setParametersList(java.util.List<java.util.Map> parametersList)
Set parameter list.Allows setting the parameter list outside this code.
- Since:
- 4.5
-
getParametersList
public java.util.List<java.util.Map> getParametersList()
Retrieve the current parameter list.- Since:
- 4.5
-
addParameters
public void addParameters(java.util.Map parameters)
Add a parameter set to the current list.Appends the parameter set to the parameter list.
- Since:
- 4.5
-
addParameters
public void addParameters(int index, java.util.Map parameters)Add a parameter set at a specified index.Inserts the parameter set into the parameter list at the specified index.
- Parameters:
index- - The index to insert into.parameter- - The parameter set to insert.- Since:
- 4.5
-
-