This discussion is archived
0 Replies Latest reply: Nov 12, 2012 3:03 AM by 971908 RSS

XML Publisher Integration: OAF Page in invalid after PDF creation

971908 Newbie
Currently Being Moderated
Hello,

after days of googling and trying out various code changes in vain I hope to find help in this forum.

The requirement is to extend the shipment page PosAsnMainPage in iSupplier Portal, adding the creation and download of PDF shipping documents for the orders selected in the table. These documents can be created for multiple shipments at once, always resulting in exactly one PDF file.

To achieve this, I have added a button to the page that triggers the event "XxpoPrintShippingDocuments". In the controller class that extends the standard iSupplier Portal Controller, I have extended processFormRequest as follows:

public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processFormRequest(pageContext, webBean);

[...]

if(strEvent.equals("XxpoPrintShippingDocuments") && ("Y").equals(pageContext.getProfile("XXPO_DROPSHIPDOCUMENTS_SECURITY")))
outputDropshipDocuments();

}//end processFormRequest


private void outputDropshipDocuments()
{
/*
* on the view object, compose a list of PoHeaderId, PoLineId, LineLocationId from the rows that were selected
*/
OAViewObject vo = (OAViewObject) am.findViewObject("PosShipmentsVO");

[...]

/*
* Create PDF and a pop-up window for download
*/
//file info
String fileName = pageContext.getMessage("XXPO", "XXPO_SD_FILENAME", null);
String fileType = "PDF";
boolean appendDate = true;

//template info
String appName = getApplicationName(vendorSiteId);
String templKey = getTemplateKey(vendorSiteId);

//user info
Integer userId = new Integer(pageContext.getUserId());

try

XxpoShippingDocumentsOut out = new XxpoShippingDocumentsOut(pageContext, webBean);

/*
* Save the printed status
*
* This is supposed to be done here instead of during xml generation.
* If any uncaught exception occurs before, the printed status remains unchanged.
*/
Class printClasses[] = {Map.class, Integer.class};
Serializable printParams[] = {selectedOrders, userId};
am.invokeMethod("savePrintStatus", printParams, printClasses);

out.setFileInfo(fileName, fileType, appendDate);
out.outputFile(xmlDoc, templKey, appName);

} catch (Exception e)
{
throw new OAException(e.getMessage(), OAException.WARNING);
}

[...]
}

Finally, in XxpoShippingDocumentsOut.outputFile there is the following code:

public void outputFile(XMLDocument xmlDoc, String templateKey, String appName)
{
[...]

try {
ServletOutputStream os = response.getOutputStream();

response.setHeader("Content-Disposition", contentDisposition);
response.setContentType(contentType);


ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
xmlDoc.print(outputStream);
ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
ByteArrayOutputStream File = new ByteArrayOutputStream();


OADBTransactionImpl transaction = (OADBTransactionImpl) am.getOADBTransaction();
TemplateHelper.processTemplate(
transaction.getAppsContext(),
appName,
templateKey,
transaction.getUserLocale().getLanguage(),
transaction.getUserLocale().getCountry(),
inputStream,
outputType.byteValue(),
null,
File);


/*
* write the output to the HttpServletResponse object and flush -
* this creates the pop-up window
*/
byte[] b = File.toByteArray();

response.setStatus(HttpServletResponse.SC_OK);
response.setContentLength(b.length);

os.write(b, 0, b.length);
os.flush();
os.close();


} catch (Exception e) {
response.setContentType("text/html");
throw new OAException(e.getMessage(), OAException.ERROR);
}

}

Most of this works just fine - I select some orders on the standard iSP page, press the button and download the PDF file. But after that, the page is not "valid" any longer: the selections made are still visible but when a button is pressed (for instance the Create Shipment Notice or my own button), I get an error stating that items must be selected first.
If I deactivate the lines in outputFile that set the response or flush the output stream, I can further use the previously made selections and everything works fine - except I don't get the PDF I need, obviously.

Does anyone have an idea of what is missing here to reload the page or anything? Is there any workaround (i.e. opening the file downlad in a separate browser tab)?

I'd be grateful for any advice on this. If you wish any further information, please let me know.

Best regards,
Michelle

Edited by: 968905 on 01.11.2012 06:09

Edited by: 968905 on 12.11.2012 03:02

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points