Wednesday, July 28, 2010

java.lang.IllegalStateException: ADF_FACES-60003:Component with ID not registered for Active Data

This was hard to fix: if anyone wants the code just ask. Or if you have a better solution please post comment.

Once excel export has been clicked if we navigate around using ppr to refresh the region we get this error.

I was forced to create an export handler tag wich forces the export to happen in a new window.

Because this page is getting some hits here is some of the code (also use this method for pdf export):
Button with new listener: (xmlns:new="http://za.co.company/adf/faces/common/my" in your jsp:root)
<af:commandToolbarButton text="Export" id="ctb1" immediate="true" partialSubmit="true" icon="images/excel.jpg">
    <new:myExportCollectionActionListener exportedId="audTab" type="excelHTML" filename="audit.xls" title="Audit"/>
  </af:commandToolbarButton>

TAG:
import oracle.adfinternal.view.faces.export.ExportCollectionActionListener;
import oracle.adfinternal.view.faces.taglib.listener.ExportCollectionActionListenerTag;

public class MyExportCollectionActionListenerTag extends ExportCollectionActionListenerTag{


protected ActionListener createActionListener(){
  ExportCollectionActionListener exportListener = 
    (ExportCollectionActionListener) super.createActionListener();
  MyExportCollectionActionListener listener = new 
    MyExportCollectionActionListener(exportListener);
  return listener;
}

  protected String getTagName(){
    return "myExportCollectionActionListener";
  }
}
Actual work:

public class MyExportCollectionActionListener extends 
  ExportCollectionActionListener{

public void processAction(ActionEvent event){
 //stuff
  String exportedId = getExportedId();
  UIComponent exported = (exportedId == null) ? null : 
    event.getComponent().findComponent(exportedId);
  //stuff
   exporter = new TableExcelExporter();
   File outputFile = getTempFile(filename);
   FileOutputStream os = new FileOutputStream(outputFile);
   OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(outputFile));
   if (exporter instanceof PdfExporter){
   ((PdfExporter)exporter).exportPdf(context, os, collection, getTitle(), 
      exportedRowsType);
   } else {
     exporter.export(context, writer, collection, getTitle(), exportedRowsType);
   }
   StreamUtil.closeStreamGracefully(os);
   writer.close();
   String generatedFileNameParam = URLEncoder.encode(outputFile.getAbsolutePath(), "UTF-8");
   HttpServletRequest request = (HttpServletRequest)externalContext.getRequest();
   ExtendedRenderKitService erks =    
     Service.getRenderKitService(FacesContext.getCurrentInstance(),    
     ExtendedRenderKitService.class);
   StringBuilder script = new StringBuilder();
   script.append("window.open('")
    .append(request.getContextPath())
    .append("/export?exportedId=")
    .append(exported).append("&type=")
    .append(contentType).append("&filename=").append(filename)
    .append("&gfn=").append(generatedFileNameParam).append("');");
   erks.addScript(FacesContext.getCurrentInstance(), script.toString());
}


Other:
In the meta-inf dir create your tld, taglib.xml and delaritivecomp-metadata.xml.

Create an export servlet to render the output from the temp file.

9 comments:

  1. Hi,

    I am having a simmilar problem but when using af:fileDownloadActionListener contentType="application/x-download"
    method="#{Bean.myMethod}" filename="filename"

    where myMethod puts on the response output the content of a file(xml).

    When pressing the button a normal popup window for saving(download) a file pops up. After download, when trying to refresh the region the folowing error apears:java.lang.IllegalStateException: ADF_FACES-60003:Component with ID: pt1:r1:1:pc1:cmi1 not registered for Active Data.
    Do you think that this is the same problem as yours? I don't understand how could I make the download happened in a new window(currently the download happens in the popup window, or not?).

    Regards Corneliu

    ReplyDelete
  2. Hi,

    This is definitely the same issue, we had the same problem with the fileDownloadActionListener.


    What we did to fix this was extend our download listener to include text files, pdf and excel etc.

    Also you could just map your button to a backing bean action that will generate the file in question then invoke a window.open javascript method (see above post) that will invoke a download.

    ReplyDelete
  3. Hi,
    Thanks for your answer.

    The file that I am downloading does not exist phisicaly. I create it programaticaly(as string) and then I write it on response with outputStream.write(); Do you think that I can apply your approach on this case also?
    If yes how will the window.open('??') java script look for download a file?
    Another question is that using the java script window.open in my backing bean will be enough, or I will have to implement my own filedownloadactionlistener?
    Regards Corneliu

    ReplyDelete
  4. You don’t need to create a filedownloadactionlistener. But unfortunately I cant think of an easy way to do this but here are some options:

    1) Create a servlet to stream the file
    window.open(“/exportServlet?info=”);

    add the servlet to web.xml


    export
    yourPackage.ExportServlet

    export
    /export


    Servlet will set the header and content type then stream the output
    response.setHeader("Content-Disposition", "attachment;filename=" + filename);
    response.setContentType(“application/x-download”);
    outputStream = response.getOutputStream();
    //write stuff to outputstream here

    2) Create a new page to do the stream and include the method in the page.
    window.open(“/newPage.jspx?info=”);

    ReplyDelete
  5. Hi,

    Can you please send me the code(with myExportCollectionActionListener or if you have one with filedownload will be better), maybe seeing an entire project I will understand better how can I implement it.
    You can find my mail in the profile.
    Regards Corneliu

    ReplyDelete
  6. Hi,

    I have the same problem. Can you send me the entire project to understand better the solution?
    Regards

    ReplyDelete
  7. This comment has been removed by a blog administrator.

    ReplyDelete
  8. java.lang.IllegalStateException

    ADF_FACES-60097:For more information, please see the server's error log for an entry beginning with: ADF_FACES-60096:Server Exception during PPR, #1
    I got this problem can you help me to solve it, Please??

    ReplyDelete
  9. No problem, unfortunately what you posted is only the top of the stack trace and I would need to see the full stack trace to help. If you could post it I will try to help.

    ReplyDelete