简体   繁体   中英

Primefaces dataexporter with ui:repeat

Hi guys I'm trying to have multiple tables with their own "export" button, I generate all the datatables with a ui:repeat tags, the problem is that I need to put the ID of the table in the dataexporter's target attribute and since in JSF you can't generate the ID dynamically I cant differentiate the datatables, they all have the same ID :( :

<ui:repeat var="location" value="#{locationOwner.locations}"
                varStatus="status">


                    <h2>
                        Localidad:
                        <h:outputText value="#{location.name}" />
                    </h2>

                    <h:commandLink>
                        <p:graphicImage value="resources/images/excel.png" />
                        <h:outputLabel>Exportar</h:outputLabel>
                        <p:dataExporter type="xls" target="tablaExp"
                            fileName="pedidosEnDisponibilidad#{location.name}" />
                    </h:commandLink>

                    <p:dataTable id="tablaExp" var="storeRequest"
                        value="#{location.userRequests}">

                        <p:column>
                            <f:facet name="header">Nombre del cliente</f:facet>
                            <h:outputText value="#{storeRequest.clientName}" />
                        </p:column>

                        <p:column>
                            <f:facet name="header">Email del cliente</f:facet>
                            <h:outputText value="#{storeRequest.clientEmail}" />
                        </p:column>

                        <p:column>
                            <f:facet name="header">Número del cliente</f:facet>
                            <h:outputText value="#{storeRequest.clientNumber}" />
                        </p:column>

                        <p:column>
                            <f:facet name="header">Equipo</f:facet>
                            <h:outputText value="#{storeRequest.equipo.productName}" />
                        </p:column>

                        <p:column>
                            <f:facet name="header">Método de contacto</f:facet>
                            <h:outputText value="#{storeRequest.contactMethod}" />
                        </p:column>

                        <p:column>
                            <f:facet name="header">Fecha del pedido</f:facet>
                            <h:outputText value="#{storeRequest.requestedDate}" />
                        </p:column>


                    </p:dataTable>

            </ui:repeat>

I guess you can use the "status" variable of your <ui:repeat> and use the index.

For example:

<h:commandLink>
    <p:dataExporter type="xls" target="tablaExp#{status.index}" ... />
</h:commandLink>

<p:dataTable id="tablaExp#{status.index}" ...>

See http://docs.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/ui/repeat.html for more info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM