Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Problem: nothing works in jsp after downloading Excel.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a "search.jsp" with a commandButton to generate excel. "Report.jsp" opens up in a new window when i click on this button by running below mentioned javascript. I can download Excel successfully by clicking on Download Excel link in report,jsp. Problem is, once i close this new window, I am unable to perform any other action in "search.jsp" even if i do not perform download. If i click on any other button or link "search.jsp", it replaces whole jsp with the Downlaod Excel link. and nothing happens after that . i need to close the seesion and start all over again from login page. Does anyone has solution. It will be big help. Thanks.

JAVASCRIPT:

--------------------------------------------------------------------------------
function aaaa()
{
mywindow =window.open('report.jsf', 'popupWindow', 'width=400,height=200,left=0,top=100,screenX=0,screenY=100');
}

Following is report.jsp:

--------------------------------------------------------------------------------
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">;
<%@ taglib uri="http://java.sun.com/jsf/core"; prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html"; prefix="h"%>
<%@ taglib uri="http://www.backbase.com/2007/jsf"; prefix="bjsf" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<f:view>
<h:form>
<h:commandLink actionListener="#{searchpage.export}" value="Download Excel" />
<a href="javascript:window.close();return false;">cancel</a>
</h:form>
</f:view>
</body>
</html>

Following is export function which runs when i click on above commandlink "Download Excel":

--------------------------------------------------------------------------------
public void export(ActionEvent event) {
try {
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) context
.getExternalContext().getResponse();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition",
"attachment; filename=report.xls");
ServletOutputStream servletOutputStream = response
.getOutputStream();
WritableWorkbook workbook = Workbook
.createWorkbook(servletOutputStream);
WritableSheet sheet = workbook.createSheet("First Sheet", 0);
WritableFont lfont = new WritableFont(WritableFont.ARIAL, 10);
lfont.setBoldStyle(WritableFont.BOLD);
WritableCellFormat lformat = new WritableCellFormat(lfont);
lformat.setBackground(Colour.DARK_RED2);
lformat.setBorder(Border.ALL, BorderLineStyle.THICK);
WritableFont rfont = new WritableFont(WritableFont.ARIAL, 10);
WritableCellFormat rformat = new WritableCellFormat(rfont);
rformat.setBorder(Border.ALL, BorderLineStyle.THIN);
for (int i = 0; i < this.list.size(); i++) {
HashMap h = (HashMap) this.list.get(i);
if (i == 0) {
Set s = (Set) h.keySet();
Iterator itr = s.iterator();
int j = 1;
while (itr.hasNext()) {
Label label2 = new Label(j, 1, itr.next().toString(),
lformat);
sheet.addCell(label2);
j++;
}
}
Collection c = h.values();
Iterator itr = c.iterator();
int j = 1;
while (itr.hasNext()) {
Label label2 = new Label(j, (i 2), itr.next().toString(),
rformat);
sheet.addCell(label2);
j+;
}
}
workbook.write();
workbook.close();
context.responseComplete();

} catch (Exception e) {
e.printStackTrace();
}
}
 
He was giving me directions and I was powerless to resist. I cannot resist this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic