views:

17

answers:

0

I've got a basic file download action that is working in the standalone version of my Struts2 webapp, but when I try to use it in the portlet version (using struts2-portlet-plugin), I'm having troubles.

First it said it didn't support "text/plain", so I added that to my portlet.xml supports section. Now it's saying java.lang.IllegalStateException: Not allowed in a portlet

Here's my basic action code:

private InputStream inputStream;

FileUtil fileUtil = new FileUtil();
private String fileName;

public String execute() {
if (StringUtils.isNotBlank(fileName)) {
    inputStream = fileUtil.retrieveFile("pathToFile" + fileName);
}

if (inputStream != null) {
    return SUCCESS;
} else {
    return ERROR;
}

//Getters & setters

And here's my action from struts.xml:
<action name="retrieveFileAction" class="RetrieveFileAction">
<result name="success" type="stream">
<param name="contentDisposition">attachment;filename="${fileName}"</param>
</result> </action>

This works great in plain Struts2. I click the link, and my file downloads. What do I need to do to get it working in a portlet?