2

I'm using the struts2 jasperreports plugin and it works well. The problem is that I want to pass exportParameters and I'm not sure how to do that through the plugin.

1
  • see my updated post that is all you have to do to use those export parameters Nov 26, 2011 at 20:31

1 Answer 1

6

Which version of Struts2 you are using starting with 2.1.2+ it provides the feature to provides exportParameters

All you need to add following entry or similar entry in your struts config file inside your action class

<action name="myJasperTest" class="com.acme.test.action.JasperAction">
    <result name="success" type="jasper">
      <param name="location">foo.jasper</param>
      <param name="dataSource">mySource</param>
      <param name="exportParameters ">exportParameters </param>
    </result>
</action>

exportParameters - OGNL expression used to retrieve a map of JR exporter parameters from the value stack. The export parameters are used to customize the JR export. For example, a PDF export might enable encryption and set the user password to a string known to the report creator. All you need to define a map for your export parameters in your action class and provides its getter/setter than use its reference as described.

For details refer this URL

jasperreports

**Update**

Here is how they have done it in result type

 exporter = new JRXlsExporter();
Map exportParams = (Map) stack.findValue(exportParameters);
             if (exportParams != null) {
                 LOG.debug("Found export parameters; adding to exporter parameters...");
                 exporter.getParameters().putAll(exportParams);
            }

so what they did is they tried to find out a map in value stack with name exportParameters if they find it they are adding it.So have to do this in your action class

Map<String,String> exportParameters= //init your map here

set your properties in this map and create a getter and setter for this property

getExportParameters()
setExportParameters()

and in your struts config file declare the map as follows

<param name="exportParameters ">exportParameters </param>

rest framework will take care Hope this will help you

11
  • but how to define the exportParameters itself
    – Moe
    Nov 24, 2011 at 9:58
  • what are your export parameters?? Nov 24, 2011 at 10:01
  • here are the parameters i want to add
    – Moe
    Nov 24, 2011 at 12:55
  • exporter = new JRXlsExporter(); exporter.setParameter(JRXlsExporterParameter.IS_COLLAPSE_ROW_SPAN, Boolean.TRUE); exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS, Boolean.TRUE); exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE); exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE); exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.FALSE); exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
    – Moe
    Nov 24, 2011 at 12:55
  • You need to set them in your action and in config file do it like <param name="exportParameters">exporter</params> all it need that this "exporter" should be in value stack so that OGNL can fetch it from there Nov 24, 2011 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.