Bonjour,
J'utilise Primefaces et je souhaiterais pouvoir downloader un fichier xml qui contient le texte que j'aurais écrit dans un inputtextarea.
La partie téléchargement fonctionne mais je ne sais pas comment faire pour que le fichier xml contienne ce que j'ai écris dans l'input.
Est ce que un développeur saurait m'aider svp ?
Merci de bien vouloir trouver ci après mon code :
La vue :
Le bean :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui"> <h:head> <title>File Download</title> </h:head> <h:body> <p:dialog modal="true" widgetVar="statusDialog" header="Status" draggable="false" closable="false" resizable="false"> <p:graphicImage value="/images/loading11.gif" /> </p:dialog> <p:inputTextarea id ="mytheinput" value="#{fileDownloadView.mytext}" cols="115" autoResize="true" rows="20" /> <h:form> <p:commandButton value="Download" ajax="false" onclick="PrimeFaces.monitorDownload(start, stop);" icon="ui-icon-arrowthick-1-s"> <p:fileDownload value="#{fileDownloadView.file}" /> </p:commandButton> </h:form> <script type="text/javascript"> function start() { PF('statusDialog').show(); } function stop() { PF('statusDialog').hide(); } </script> </h:body> </html>
Cordialement.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 @ManagedBean(name="fileDownloadView") public class FileDownloadView { private StreamedContent file; private String mytext; public FileDownloadView() { InputStream stream = ((ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext()).getResourceAsStream(mytext); file = new DefaultStreamedContent(stream, "xml", "yourfile.xml"); } public StreamedContent getFile() { return file; } public String getMytext() { return mytext; } }
Partager