Java 如何从InputExtArea下载包含内容的xml文件?
我正在尝试使用primefaces组件下载一个xml文件。这部分工作正常,但我的页面上有一个InputExtArea,我想让我在InputExtArea中编写的文本写入下载的xml文件中。开发人员可以帮助我吗?多谢各位 我的看法是:Java 如何从InputExtArea下载包含内容的xml文件?,java,xml,jsf,primefaces,download,Java,Xml,Jsf,Primefaces,Download,我正在尝试使用primefaces组件下载一个xml文件。这部分工作正常,但我的页面上有一个InputExtArea,我想让我在InputExtArea中编写的文本写入下载的xml文件中。开发人员可以帮助我吗?多谢各位 我的看法是: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.
<!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>
几句话
p:inputExtArea
应该在h:form
元素中mytext
属性必须有getter(确定)和setter(缺少!)InputStream
(即在getFile
内部而不是构造函数中)public StreamedContent getFile() {
InputStream stream = new ByteArrayInputStream( mytext.getBytes() );
StreamedContent file = new DefaultStreamedContent(stream, "xml", "yourfile.xml");
return file;
}
public String getMytext() {
return mytext;
}
public void setMytext(String mytext) {
this.mytext = mytext;
}
public StreamedContent getFile() {
InputStream stream = new ByteArrayInputStream( mytext.getBytes() );
StreamedContent file = new DefaultStreamedContent(stream, "xml", "yourfile.xml");
return file;
}
public String getMytext() {
return mytext;
}
public void setMytext(String mytext) {
this.mytext = mytext;
}