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.

JBO-25014 - Another user changed row

Check your columns that are set by defaults and triggers are always update in your EO