2

I am trying to use Prime Faces data exporter component:

<p:dataExporter type="xls" target="table_name" fileName="summaries"/>  

It would seem that the target attribute needs to point to the id of a data table. On my page I have a composite component which gets included twice. It takes one parameter which tells it where to get its data from. So the composite component renders the same table twice, but with different data.

I want the exporter for both tables. In my composite component I have:

<p:dataTable id="overview"

Of course when this is rendered twice JSF generates the id dynamically e.g.

form:tabView:j_id1693604892_4df53909:overview

Is there any way I can get the Prime Faces data exporter to work in this circumstance ?

Thanks.

4

1 回答 1

0

来自 DataExporter.java 的代码(Primefaces 源代码已简化)

String tableId = (String) target.getValue(elContext);

Exporter exporter = ExporterFactory.getExporterForType(exportAs);

UIComponent component = event.getComponent().findComponent(tableId);

if(component == null) {
    throw new FacesException("Cannot find component \"" + tableId + "\" in view.");
}

if(!(component instanceof DataTable)) {
    throw new FacesException("Unsupported datasource target:\"" + component.getClass().getName() + "\", exporter must target a PrimeFaces DataTable.");
}

DataTable table = (DataTable) component;
exporter.export(context, table, outputFileName, isPageOnly, isSelectionOnly, encodingType, preProcessor, postProcessor);

所以不支持多个组件。

你可以尝试什么:

  1. 将数据表 ID 作为单独的参数传递给您的复合组件。

  2. 为您的复合组件提供 id。因为它是一个命名容器,所以它将这个 id 附加到它的子组件中。这样您就可以随意引用它。

于 2013-02-18T14:53:30.217 回答