Primefaces数据导出器:导出数据问题

时间:2016-11-23 04:14:14

标签: primefaces jsf-2

我有一份清单。让我们说学生和地址。一对多的关系。在我的数据表中,有3列用于姓名,姓氏,年龄与学生相关,在一个列中,我需要显示地址,并连接以下字段,如地址1,地址2,城市,国家。现在我需要导出这个表格使用<p:dataExporter>。当我尝试导出为Excel时,相应的地址列将导出为Object(org.primefaces.uirepeat .blah blah ..)

我的代码是

<p:dataTable value="#{manager.studentList}" var="item" id="studentData">
            <p:column>
                <f:facet name="header">Name</f:facet>
                <h:outputText value="#{item.name}" />
            </p:column>
            <p:column>
                <f:facet name="header">Surname</f:facet>
                <h:outputText value="#{item.surname}" />
            </p:column>
            <p:column>
                <f:facet name="header">Age</f:facet>
                <h:outputText value="#{item.age}" />
            </p:column>
            <p:column>
                <f:facet name="header">Address</f:facet>
               <ui:repeat value="#{studentBean.addressList}" var="address">
                <h:outputText value="#{address.address1}" /> <br />
               <h:outputText value="#{address.address2}" /> <br />
                <h:outputText value="#{address.city}" /> <br />
               <h:outputText value="#{address.country}" />
               </ui:repeat>
            </p:column> 
        </p:dataTable>

        <h:commandLink>
        <p:graphicImage name="/images/excel.png" />
        <p:dataExporter type="xls" target="studentData" fileName="studentdetails" pageOnly="true"/>
    </h:commandLink>

建议我出口一些方法。甚至我尝试使用c:forEach和columns。

1 个答案:

答案 0 :(得分:0)

<p:dataTable value="#{manager.studentList}" rowIndexVar="index" var="item" id="studentData">
        <p:column>
            <f:facet name="header">Name</f:facet>
            <h:outputText value="#{item.name}" />
        </p:column>
        <p:column>
            <f:facet name="header">Surname</f:facet>
            <h:outputText value="#{item.surname}" />
        </p:column>
        <p:column>
            <f:facet name="header">Age</f:facet>
            <h:outputText value="#{item.age}" />
        </p:column>
        <p:column>
            <f:facet name="header">Address</f:facet>
            <c:forEach var="address" items="#{studentBean.addressList.get(index).address}">
                <h:outputText value="#{address.address1}" />,
                <h:outputText value="#{address.address2}"/>,
                <h:outputText value="#{address.city}" />,
                <h:outputText value="#{address.country}" />
            </c:forEach>
        </p:column> 
    </p:dataTable>

    <h:commandLink>
    <p:graphicImage name="/images/excel.png" />
    <p:dataExporter type="xls" target="studentData" fileName="studentdetails" pageOnly="true"/>
</h:commandLink>

我尝试用c:forEach是好的

相关问题