I am trying to create a FileDownload from bean just like this commandLike and image.
CommandLink cl = new CommandLink();
cl.setAjax(false);
cl.setTitle(downloads.getDownload());
and
GraphicImage img = new GraphicImage();
img.setAlt(descricao);
They are working fine.
The problem with FileDownload is that It doesnt have a class extended from UIComponent.
So, I Cant add it to a Panel for example.
Differente from the other It doesnt have a FileDownload Class only the FileDownloadTag and FileDownloadTagHandler.
What Can I use instead?
Thank you
FileDownload from Bean
-
- Prime
- Posts: 18616
- Joined: 05 Jan 2009, 00:21
- Location: Cybertron
- Contact:
FileDownload is not a component but an actionListener.
Code: Select all
FileDownloadActionListener fl = new FileDownloadActionListener();
commandLink.addActionListener(fl);
Just a question
The method of generation of the DefaultStrem is configured at the CommandLinkm Right??
I have got this code
Everything is ok, but when i do the click, the page is refreshed and the download method (factoryController.download()) is not called;
The method of generation of the DefaultStrem is configured at the CommandLinkm Right??
I have got this code
Code: Select all
HtmlForm form = new HtmlForm();
form.setStyle("border-style:solid;");
form.setPrependId(false);
CommandLink cl = new CommandLink();
cl.setAjax(false);
cl.setTitle(downloads.getDownload());
//cl.setValueExpression("value", FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{factoryController.downloads('"+ downloads.getIddownload() +"')}", StreamedContent.class));
Imagem img = new Imagem(downloads.getImagem().getIdimagem(), null, null, null);
cl.getChildren().add(img.getUIObject());
FileDownloadActionListener fl = new FileDownloadActionListener(FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{factoryController.downloads('"+ downloads.getIddownload() +"')}", StreamedContent.class), null);
cl.addActionListener(fl);
form.getChildren().add(cl);
return form;
this code is at, factoryController
public StreamedContent downloads(long download) {
return new DefaultStreamedContent(new ByteArrayInputStream(((Downloads) genericDao.getById(Downloads.class, download)).getArquivo()), "");
}
Tomcat 7 + jsf-api - 2.0.3-SNAPSHOT + Primefaces 2.1
Sorry About de Message again but, I did the code below and got no erros, but the download method for generating the DefaultInputStream is not being called
factoryController.downloads is not being called
Thank you
Code: Select all
HtmlForm form = new HtmlForm();
form.setPrependId(true);
CommandLink cl = new CommandLink();
cl.setAjax(false);
cl.setTitle(downloads.getDownload());
cl.setActionExpression(FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "#{factoryController.downloads('"+ downloads.getIddownload() +"')}", StreamedContent.class, new Class<?>[0]));
Imagem img = new Imagem(downloads.getImagem().getIdimagem(), null, null, null);
cl.getChildren().add(img.getUIObject());
FileDownloadActionListener fl = new FileDownloadActionListener();
cl.addActionListener(fl);
form.getChildren().add(cl);
Thank you
Tomcat 7 + jsf-api - 2.0.3-SNAPSHOT + Primefaces 2.1
Sorry Again about the many posts but deeper in the problem, I have find that, when I do the FileUpload by tags It works fine because processAction of FileDownloadActionListener is being done.
When I just type it programatically the download Listener is called with the same params but the processAction is not being called. They go directelly to the saveState.
Thank you
When I just type it programatically the download Listener is called with the same params but the processAction is not being called. They go directelly to the saveState.
Thank you
Tomcat 7 + jsf-api - 2.0.3-SNAPSHOT + Primefaces 2.1
-
- Posts: 21
- Joined: 15 Dec 2010, 07:53
Hey i met with a different issue, File download component works fine for the first time when i download the file.But from the second time the whole jsf page is getting downloaded (instead of the downloaded file.)
Iam using view scoped is this was the problem. But i tried in different scopes such as session ,request.
Also iam currently using p:command link.
Iam using view scoped is this was the problem. But i tried in different scopes such as session ,request.
Also iam currently using p:command link.
-
- Information
-
Who is online
Users browsing this forum: No registered users and 19 guests