Win a copy of TDD for a Shopping Website LiveProject this week in the Testing 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

File Download problem using icefaces

 
Ranch Hand
Posts: 362
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 25461
180
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I'm doing laundry! Look how clean this tiny ad is:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic