Hi Expert,
I need help.
I created a custom button to download data to an excel sheet. after clicking the button I am getting message
"An error occurred; please try again. If the error persists, please contact technical support.".
I tried debugging WCEM, but it is not even reaching that point.
Your help will be highly appreciated.
here is the code.
BitContentview.XHTML
<wec:commandButton id="bdtexcel" immediate="true" actionListener="#{cc.vch.DownloadBITData}" type="submit" value="#{i18n['invoices.ui.openitems.printSelected']}"/> |
UI-repository.xml
<ViewComponent name="BITContentView" componentHandlerClassName="com.cpr.cprwec.app.comm.module.ebpp.ui.handler.impl.BITDetailViewVCHandler"/>
BITDetailViewVCHnadler.java
package com.cpr.cprwec.app.comm.module.ebpp.ui.handler.impl;
import com.cpr.cprwec.app.comm.module.ebpp.backendobject.interf.EbppBackend;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.faces.context.FacesContext;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import com.cpr.cprwec.app.comm.module.ebpp.modulemgmt.impl.EbppModuleAccessImpl;
import com.cpr.cprwec.app.comm.module.ebpp.modulemgmt.interf.EbppModuleAccess;
import com.cpr.cprwec.app.comm.module.ebpp.ui.dto.impl.DisputeDataDTOImpl;
import com.cpr.cprwec.app.comm.module.ebpp.ui.dto.impl.OpenItemDTOImpl;
import com.cpr.cprwec.app.comm.module.ebpp.ui.dto.interf.DisputeDataDTO;
import com.cpr.cprwec.app.comm.module.ebpp.ui.dto.interf.OpenItemDTO;
import com.cpr.cprwec.app.comm.module.ebpp.ui.dto.impl.BITDataDTOImpl;
import com.cpr.cprwec.app.comm.module.ebpp.ui.dto.interf.BITDataDTO;
import com.cpr.cprwec.app.comm.module.ebpp.ui.dto.impl.BITDetailDTOImpl;
import com.cpr.cprwec.app.comm.module.ebpp.ui.dto.interf.BITDetailDTO;
import com.sap.wec.app.common.module.common.attachment.businessobject.interf.Attachment;
import com.sap.wec.tc.core.backend.sp.jco.JCoConnection;
import com.sap.wec.tc.core.businessobject.BusinessObjectException;
import com.sap.wec.tc.core.common.exceptions.ApplicationBaseRuntimeException;
import com.sap.wec.tc.core.common.logging.WCFLocation;
import com.sap.wec.tc.core.common.searching.businessobject.impl.GenericSearch;
import com.sap.wec.tc.core.common.searching.businessobject.interf.GenericSearchReturnResultData;
import com.sap.wec.tc.core.common.util.GenericFactory;
import com.sap.wec.tc.core.common.util.Message;
import com.sap.wec.tc.core.common.util.MessageList;
import com.sap.wec.tc.core.common.util.table.Table;
import com.sap.wec.tc.core.common.util.table.TableRow;
import com.sap.wec.tc.core.modulemgmt.ForeignModuleAccess;
import com.sap.wec.tc.core.modulemgmt.ModuleAccess;
import com.sap.wec.tc.core.modulemgmt.exceptions.ModuleInactiveException;
import com.sap.wec.tc.core.modulemgmt.exceptions.ModuleLifecycleException;
import com.sap.wec.tc.core.runtime.WecFrameworkRuntime;
import com.sap.wec.tc.core.runtime.WecSession;
import com.sap.wec.tc.core.runtime.jsf.WecFrameworkRuntimeJSF;
import com.sap.wec.tc.core.runtime.jsf.composition.PageManagerBean;
import com.sap.wec.tc.core.runtime.navigation.NavigationCondition;
import com.sap.wec.tc.core.ui.composition.menu.MenuManager;
import com.sap.wec.tc.core.ui.composition.menu.MenuMetadataException;
import com.sap.wec.tc.core.ui.vc.BuildTime;
import com.sap.wec.tc.core.ui.vc.NavigationParameterBinding;
import com.sap.wec.tc.core.ui.vc.RequestParameterBinding;
import com.sap.wec.tc.core.ui.vc.impl.ViewComponentHandlerBaseImpl;
import com.cpr.cprwec.app.comm.module.ebpp.businessobject.interf.BIT;
import com.cpr.cprwec.app.comm.module.ebpp.businessobject.impl.BITImpl;
public class BITDetailViewVCHandler extends
ViewComponentHandlerBaseImpl<EbppModuleAccess> {
protected static final WCFLocation LOCATION = WCFLocation
.getInstance(BITDetailViewVCHandler.class.getName());
public BITDataDTO bitDataDTO;
public BITDetailDTO bitDetailDTO;
public List<BITDataDTO> BITDataDTOList;
public List<BITDetailDTO> BITDetailDTOList;
public boolean noBITData;
public boolean noBITDetail;
public boolean renderPanel = true;
public boolean isDownloadBITData;
public boolean isDownloadBITDetail;
public boolean downloadStarted=false;
public boolean BITFound =false;
public boolean isBITFound() {
return BITFound;
}
public void setDownloadStarted( boolean downloadStarted ){
this.downloadStarted = downloadStarted;
}
public boolean getDownloadStarted(){
return this.downloadStarted;
}
public void setBITFound(boolean BITFound) {
this.BITFound = BITFound;
}
public String getObjectID() {
return objectID;
}
public void setObjectID(String objectID) {
this.objectID = objectID;
}
public List<BITDataDTO> getBITDataDTOList() {
return BITDataDTOList;
}
public List<BITDetailDTO> getBITDetailDTOList() {
return BITDetailDTOList;
}
public Boolean getNoBITData() {
return noBITData;
}
public Boolean getNoBITDetail() {
return noBITDetail;
}
public Boolean getRenderPanel() {
return renderPanel;
}
private static final int DEFAULT_BUFFER_SIZE = 1024000;
public Attachment attachmentData;
public Attachment getAttachmentData() {
return attachmentData;
}
@RequestParameterBinding(maxLength = 1024)
protected String objectID;
@BuildTime
public String processBuildTime() throws BusinessObjectException {
BIT BIT = null;
noBITData = noBITDetail = false;
renderPanel = true;
if (isLoggedIn()) {
if ( isDownloadBITData == true ){
this.downloadBITDataExcel();
}
else {
this.getModuleAccess().getBITBO().clearMessages();
BIT = this.moduleAccess.getBITBO().getBITFromBackend(objectID);
BITDataDTOList = BIT.getBITDataDTOList();
BITDetailDTOList = BIT.getBITDetailDTOList();
}
MessageList objectData = this.getModuleAccess().getBITBO()
.getMessageList();
if (objectData.size() > 0) {
noBITData = noBITDetail = true;
renderPanel = false;
this.addMessageList(objectData);
}
}
return checkLoginCondition();
}
private boolean isLoggedIn() {
return checkLoginCondition() == null;
}
private String checkLoginCondition() {
NavigationCondition navCondition = getNavigationCondition("login");
if (!navCondition.isFullfiled()) {
navCondition.addToNavigationStack();
return navCondition.getOutcome();
}
return null;
}
public String downloadBITData(){
downloadStarted = true;
isDownloadBITData = true;
downloadBITDataExcel();
return checkLoginCondition();
}
public void downloadBITDataExcel() {
// dummyDebug("downloadBITDataExcel", BITDataDTOList.size(), "", "" );
if (BITDataDTOList.size() > 0) {
try {
attachmentData = this.getModuleAccess().getDownloadBO()
.getBITDataExcel(BITDataDTOList);
if (attachmentData != null) {
FacesContext faces = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) faces
.getExternalContext().getResponse();
response.reset();
response.setContentType(attachmentData
.getAttachmentMimeType());
response.setContentLength(attachmentData
.getAttachmentContent().length);
response.setHeader("Content-disposition",
"attachment;filename="
+ attachmentData.getAttachmentName());
response.setBufferSize(DEFAULT_BUFFER_SIZE);
ServletOutputStream out;
try {
out = response.getOutputStream();
out.write(attachmentData.getAttachmentContent());
out.flush();
faces.responseComplete();
} catch (IOException e) {
throw new ApplicationBaseRuntimeException(
"Problem opening file", e);
} finally {
attachmentData = null;
}
}
} catch (BusinessObjectException e) {
e.printStackTrace();
}
}
isDownloadBITData = false;
}