Full controller support in Java

Enonic version: 6.4.1
OS: Debian Jessie

I have a service that needs to support export to excel, I am using Apache POI for this. Is it possible to pass full control of the response to Java code (need to return a stream with Content-Disposition header)?

Hi.

Right now it’s not, but we are planning support for this. What you can do right now is to create a javascript controller that delegates to a java class for processing.

var myBean = __.newBean('com.foo.bar.ExcelExporter');

exports.get = function(req) {
    return {
        body: myBean.toExcel(),
        headers: {
            'Content-Disposition': '...'
        }
    };
}

The trick here is to let toExcel method on com.foo.bar.ExcelExporter return a guava ByteSource or a byte[] array. This will ensure that the bytes are returned by the controller.

In the future we will support some sort of controller-delegation to Java where you can set headers, body and pageContributions in java.

1 Like

That worked fine, thanks!

Now to the next step, I need to be able to accept a excel workbook from form post and pass it into my Java code to update existing content, could you describe how to do that ?

Great to hear.

Is this workbook a multipart form-upload?

Yes it is…

You can look at the documentation for multipart upload:

If you want to do this in Java, you can get hold of the HttpServletRequest and MultipartService then get the MultipartForm from that service. See javadoc here:

1 Like