How to download a xml file with content from inputtextarea?



I am trying to download a xml file using primefaces components. This part is working but I have on my page a inputtextarea, and I would like to have the text that I write in the inputtextarea written in the xml file that is downloaded. Could a developer help me ? Thank you.


my view :



<!DOCTYPE html>
<html xmlns="http://ift.tt/lH0Osb"
xmlns:ui="http://ift.tt/KsEgXx"
xmlns:h="http://ift.tt/HjFrZb"
xmlns:f="http://ift.tt/HcrI1S"
xmlns:p="http://ift.tt/HjFrZc">


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


My bean :



@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;
}

}

No comments:

Post a Comment