我想为动态列添加导出。 我认为应该去。 Dynamic Columns Export Data
我使用了Primefaces的示例代码并对其进行了编辑:Primefaces Example
本规范有效,但数据不正确。
文件包含动态数据,如data[i], data[i], ....
,而不是data [i]中的属性。
有什么想法吗?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:my="http://java.dynamic.list.de"
xmlns:p="http://primefaces.org/ui">
<ui:composition template="META-INF/templates/Template.xhtml">
<ui:define name="content">
<h:form id="form" enctype="multipart/form-data">
<h:panelGrid columns="3">
<h:selectOneMenu id="showColl" value= "#{searchBean.collList.currentColl}" rendered = "#{searchBean.search.visible}">
<f:selectItems value="#{searchBean.collList.collList}" />
</h:selectOneMenu>
<h:outputText value="#{msgs.collection}" rendered = "#{searchBean.search.hide}"></h:outputText>
<h:outputText value="#{searchBean.collList.currentColl}" rendered = "#{searchBean.search.hide}"></h:outputText>
<h:commandButton id="show" action="#{searchBean.showFieldList}" value="#{msgs.plus}" rendered="#{searchBean.search.visible}" style=""/>
<h:commandButton id="hide" action="#{searchBean.hideFieldList}" value="#{msgs.minus}" rendered="#{searchBean.search.hide}" immediate="true" onchange="this.form.submit()" style=""/>
</h:panelGrid>
<h:panelGrid columns="1" rendered="#{searchBean.search.hide}">
<h:panelGrid columns="2">
<h:outputLabel value="#{msgs.Attr}"></h:outputLabel>
<h:selectOneMenu id="Field"
value="#{searchBean.collList.currentField}"
rendered="#{searchBean.search.readWrite}">
<f:selectItems
value="#{searchBean.collList.fieldList}" />
</h:selectOneMenu>
<h:outputText value="#{searchBean.collList.currentField}" rendered="#{searchBean.search.readOnly}"></h:outputText>
</h:panelGrid>
<h:panelGrid columns="2">
<h:outputLabel value="#{msgs.value}"></h:outputLabel>
<h:inputText value="#{searchBean.search.value}" rendered = "#{searchBean.search.readWrite}"></h:inputText>
<h:outputText value="#{searchBean.search.value}" rendered = "#{searchBean.search.readOnly}"></h:outputText>
</h:panelGrid>
<h:panelGrid columns="3">
<h:outputText value="#{msgs.sort_Order}"/>
<h:selectOneRadio id="sortOrder"
value="#{searchBean.search.ascendingData}"
immediate="true" onchange="this.form.submit()">
<f:selectItem itemLabel="#{msgs.ascending}" itemValue="a" itemDisabled="#{searchBean.search.readOnly}"/>
<f:selectItem itemLabel="#{msgs.descending}" itemValue="d" itemDisabled="#{searchBean.search.readOnly}"/>
</h:selectOneRadio>
</h:panelGrid>
</h:panelGrid>
<h:commandButton id="search" action="#{searchBean.searchButton}" value="#{msgs.search}" style=""/>
<p:dataTable id="datas" var="data" value="#{searchBean.readListMap.items}" style="width:150px"
scrollable="true" scrollWidth="800" scrollHeight="400" emptyMessage="Keine Daten vorhanden">
<p:columns value="#{searchBean.collList.fieldListColumns}" var="columnName" columnIndexVar="i" style="width:150px" headerText="#{columnName}">
#{data[i]}
</p:columns>
</p:dataTable>
<h:commandLink>
<p:graphicImage library="images" name="csv.png" />
<p:dataExporter type="csv" target="datas" fileName="assetDB" />
</h:commandLink>
<h:commandLink>
<p:graphicImage library="images" name="xml.png" />
<p:dataExporter type="xml" target="datas" fileName="assetDB" />
</h:commandLink>
</h:form>
</ui:define>
</ui:composition>
</html>
答案 0 :(得分:1)
我用这段代码来创建文件。 结果我是一个StringBuilder来创建你的costum字符串。我创建了一个特定的cvs文件。
String tempString = result.toString();
InputStream stream = new ByteArrayInputStream(tempString.getBytes("UTF-8"));
Timestamp tstamp = new Timestamp(System.currentTimeMillis());
file = new DefaultStreamedContent(stream, "application/cvs", "test-"+tstamp+".cvs");
我在xhtml文件中写下了来自primefaces Primefaces example的示例。希望这有助于其他人在动态列和曲面导出数据方面遇到问题。