Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File Download problem using icefaces

 
Mary Cole
Ranch Hand
Posts: 362
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am using icefaces with liferay and am trying to download a file( it should open up the download dialogue box) from DB using the attached code. I have a command link on the webpage and currently if I click on that link, the method gets called, the inputstream is not null, but on the browser nothing happens.





Am I missing something? please help
 
pc pcqsajhd
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this might be a bit late but...

You need to tell icefaces to use the standard renderer on the page by doing the following



see the documentation here:

http://wiki.icesoft.org/display/ICE/config
 
simone santos
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am using icefaces 1.8 with liferay 5.2.3 and am trying to download a file, but the download no performs, no show error and no start download, no
Please can someone help me does nothing
x is list of data, I have on datatable that the user will select the file for download can be all ou one file

public void download() {

List<File> files = new ArrayList<File>();
for (Dados dado : x) {
if (dado.isMarcador()) {
File file = new File(dado.getCaminho());
if (file.exists()) {
files.add(file);
}
}
}
if (!files.isEmpty()) {
System.out.println(files);
download1(files);
}
}



private static final int DEFAULT_BUFFER_SIZE = 10240; // 10KB.

private void download1(List<File> files) {


PortletResponse portletResponse = (PortletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
HttpServletResponse response = PortalUtil.getHttpServletResponse(portletResponse);

response.setContentType("application/zip");
response.setHeader("Content-Disposition", "attachment; filename=\"allfiles.zip\"");
ZipOutputStream output = null;
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];

try {
output = new ZipOutputStream(new BufferedOutputStream(response.getOutputStream(), DEFAULT_BUFFER_SIZE));

for (File file : files) {
InputStream input = new FileInputStream(file);
System.out.println(file);
try {
input = new BufferedInputStream(input, DEFAULT_BUFFER_SIZE);
output.putNextEntry(new ZipEntry(file.getName()));
for (int length = 0; (length = input.read(buffer)) > 0;) {
output.write(buffer, 0, length);
// System.out.println("wrote: "+length);
}
output.closeEntry();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException logOrIgnore) { /*
*
*/ }
}
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (output != null) {
try {
System.out.println("fechou");
output.flush();
output.close();
FacesContext.getCurrentInstance().responseComplete();
} catch (IOException logOrIgnore) { /*
*
*/ }
}
}
}

<!-- <h:commandButton value="Download Selected" action="#{selectt.download}" rendered="#{selectt.displayFor}"/>



Please help me
thank you
 
Tim Holloway
Saloon Keeper
Posts: 18365
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Simone!

A couple of hints. Rather than append to an old message thread (which we call "resurrecting a zombie"), it's better to start a thread of your own. Also, we have a "Code" button that can wrap special tags around code and XML samples, which helps make them more readable.

As a general rule, you should not use JSF to produce downloaded content. Use a traditional servlet for that purpose. JSF won't mind. It can even provide data for the servlet using shared session-scope beans.

JSF is designed to produce HTML forms and similar content. If you attempt to force it to produce non-HTML output, the code tends to be both ugly and unreliable. A servlet can do it much more simply and you're less likely to see things break when new versions of JSF come along.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic