FileDownload from Bean

UI Components for JSF
Post Reply
lmmoreira
Posts: 60
Joined: 08 Jul 2010, 14:15

07 Oct 2010, 16:15

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
Tomcat 7 + jsf-api - 2.0.3-SNAPSHOT + Primefaces 2.1

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

07 Oct 2010, 16:42

FileDownload is not a component but an actionListener.

Code: Select all

FileDownloadActionListener fl = new FileDownloadActionListener();

commandLink.addActionListener(fl);

lmmoreira
Posts: 60
Joined: 08 Jul 2010, 14:15

07 Oct 2010, 19:29

Just a question

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()), "");
    }



Everything is ok, but when i do the click, the page is refreshed and the download method (factoryController.download()) is not called;
Tomcat 7 + jsf-api - 2.0.3-SNAPSHOT + Primefaces 2.1

lmmoreira
Posts: 60
Joined: 08 Jul 2010, 14:15

08 Oct 2010, 16:05

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

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);

factoryController.downloads is not being called

Thank you
Tomcat 7 + jsf-api - 2.0.3-SNAPSHOT + Primefaces 2.1

lmmoreira
Posts: 60
Joined: 08 Jul 2010, 14:15

08 Oct 2010, 19:24

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
Tomcat 7 + jsf-api - 2.0.3-SNAPSHOT + Primefaces 2.1

harish.seipl
Posts: 21
Joined: 15 Dec 2010, 07:53

26 Apr 2011, 08:13

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.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 19 guests