p:downloadFile and viewScope

UI Components for JSF
Post Reply
jby43
Posts: 4
Joined: 01 Dec 2011, 11:36

01 Dec 2011, 11:41

Hello everybody,

I want to download a file with primefaces, everything works but nothing happens on the browser.

here is my xhtml:

Code: Select all

 <p:commandLink title="Download file" action="#{msgBoxBean.selectMessage}" process="@this" update="@none" >  
                            <img src="#{resource['img:icon_document_flat_download.gif']}" alt="#{msg['mcn.inbox.flat.file.download']}}"/>     
                            <f:setPropertyActionListener target="#{msgBoxBean.selectedMessage}" value="#{message}" /> 
                            <p:fileDownload value="#{msgBoxBean.downloadPrincipalFile}"/>
                        </p:commandLink>
I use process="@this" update="@none" because otherwise my commandLink is never execute

here is my bean (managed bean - view scoped) I also use CDI bean and conversationScoped but it is also not working

Code: Select all

@ManagedBean(name = "msgBoxBean")
@ViewScoped
public class MsgBoxBean implements Serializable {

    Logger logger = LoggerFactory.getLogger(MsgBoxBean.class);

    private Message selectedMessage;

    public MsgBoxBean() {
    }

    @PostConstruct
    public void initServices() {
       

    }

    public StreamedContent getDownloadPrincipalFile() {
        logger.debug("start getDownloadPrincipalFile");

        ByteArrayInputStream content = null;
                /// some stuff to create mly content
                DefaultStreamedContent file = new DefaultStreamedContent(content, "text/plain", "currentFile.txt");
              
            } 
            
           throw new AbortProcessingException();
        } catch (XPathExpressionException ex) {
            throw new DataAccessException("An unexpected exception occured while retrieve the inputStream from the following archivedId: " + selectedFile.getArchiveId(), ex);
        } catch (IOException ex) {
            throw new DataAccessException("An unexpected exception occured while retrieve the inputStream from the following archivedId: " + selectedFile.getArchiveId(), ex);
        } 

    }

    public void selectMessage() {
    }

    public Message getSelectedMessage() {
        return selectedMessage;
    }

    public void setSelectedMessage(Message selectedMessage) {
        logger.debug("set the selected message for download");
        this.selectedMessage = selectedMessage;
    }
}
The commandLink entered in each method calls but nothing happends on the screen.

Can you help me!

Jamila

jby43
Posts: 4
Joined: 01 Dec 2011, 11:36

01 Dec 2011, 13:43

It's ok ... I have delete the <f:view> reference and now it's working well

porthos
Posts: 122
Joined: 09 May 2011, 03:17

01 Dec 2011, 13:45

What <f:view> reference? It might help others if you add the relevant code to your original question.

Thanks.
-------
PrimeFaces 3.4, Glassfish 3.1.2, Mojarra 2.1.6

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 65 guests