Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从InputExtArea下载包含内容的xml文件?_Java_Xml_Jsf_Primefaces_Download - Fatal编程技术网

Java 如何从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.

我正在尝试使用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.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
    元素中
  • bean的
    mytext
    属性必须有getter(确定)和setter(缺少!)
  • InputStream代码来自返回资源图片文件内容的PF示例。您只需要从字符串创建一个流!问问你自己
  • 由于文本的变化,必须动态创建
    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;
    }