必须Primefaces Data Exporter目标是绝对id吗?

时间:2013-02-18 14:01:41

标签: java jsf java-ee primefaces java-ee-6

我正在尝试使用Prime Faces数据导出器组件:

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

似乎target属性需要指向数据表的id。在我的页面上,我有一个复合组件,包括两次。它需要一个参数来告诉它从哪里获取数据。因此,复合组件呈现两次相同的表,但具有不同的数据。

我想要两个表的导出器。在我的复合组件中,我有:

<p:dataTable id="overview"

当然,当呈现两次时,JSF会动态生成id。

form:tabView:j_id1693604892_4df53909:overview

有没有办法让Prime Faces数据导出器在这种情况下工作?

感谢。

1 个答案:

答案 0 :(得分:0)

来自DataExporter.java的代码(Primefaces source simplified)

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添加到它的子组件中,因为它是一个命名容器。这样你无论如何都可以引用它。