В попытке работать с динамическим списком и динамическим html, я построил динамическую таблицу с динамическими столбцами в таблице данных, все работает нормально и работает как требуется, за исключением того, что он не фильтрует, вместо этого он не показывает никаких записей, как некоторыетекст напечатан. ..................................
@ManagedBean(name="liveRangeService", eager = true)
@ApplicationScoped
public class LiveRangeService implements Serializable {
ResultSet RS;
dbConnectionSQLServer db;
private List< Map<String, ColumnModel> > tableData;
private Map<String, ColumnModel> selectedData;
private List< Map<String, ColumnModel> > filteredData;
public Map<String, ColumnModel> getSelectedData() {
return selectedData;
}
public void setSelectedData(Map<String, ColumnModel> selectedData) {
this.selectedData = selectedData;
}
private List<ColumnModel> tableHeaderNames;
private String tableColWidths;
private List< Map<String, ColumnModel> > selectedRow;
public List<Map<String, ColumnModel>> getTableData() {
return tableData;
}
public List<ColumnModel> getTableHeaderNames() {
return tableHeaderNames;
}
public LiveRangeService() {
}
public void LiveRangeServicesss() {
db = new dbConnectionSQLServer();
try {
tableData = new ArrayList< Map<String, ColumnModel> >();
tableHeaderNames = new ArrayList<ColumnModel>();
Statement SQL = dbConnectionSQLServer.getCN().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
RS = SQL.executeQuery("Select * From Coa32 Order BY Title");
for (int j = 0; j < RS.getMetaData().getColumnCount(); j++) {
tableHeaderNames.add(new ColumnModel("header "+j, RS.getMetaData().getColumnLabel(j+1)));
}
//Generate table data.
for (int i = 0; RS.next(); i++) {
Map<String, ColumnModel> playlist = new HashMap<String, ColumnModel>();
// System.out.println("Row : " + i );
for (int j = 0; j < RS.getMetaData().getColumnCount(); j++) {
playlist.put(tableHeaderNames.get(j).key, new ColumnModel(tableHeaderNames.get(j).key, RS.getString(j+1)));
}
tableData.add(playlist);
}
PrimeFaces.current().ajax().update("form:dlgTBL");
PrimeFaces.current().ajax().update("form:dlgTBL2");
PrimeFaces.current().executeScript("PF('dlg').show();");
} catch (SQLException e) {
System.out.println("Error !!! " + e.getMessage());
}
}
public List<Map<String, ColumnModel>> getSelectedRow() {
try {System.out.println("Selected Row! " + selectedRow.size());} catch (Exception e) {}
return selectedRow;
}
public void setSelectedRow(List<Map<String, ColumnModel>> selectedRow) {
System.out.println( "selected size: " + selectedRow.size() );
this.selectedRow = selectedRow;
}
public String getTableColWidths() {
return tableColWidths;
}
public void setTableColWidths(String tableColWidths) {
this.tableColWidths = tableColWidths;
}
public List<Map<String, ColumnModel>> getFilteredData() {
return filteredData;
}
public void setFilteredData(List<Map<String, ColumnModel>> filteredData) {
this.filteredData = filteredData;
}
}
Ниже приводится HTML-часть
<p:dialog id="dlgTBL" modal="true" showEffect="bounce" widgetVar="dlg" resizable="false">
<p:dataTable var="result" id="tbl" widgetVar="dtlTBL"
value="#{liveRangeService.tableData}"
paginator="false"
scrollable="true" rowIndexVar="index" scrollHeight="500"
scrollRows="50" liveScroll="true"
filterDelay="1100"
>
<p:ajax event="rowSelect" listener="#{indexBean.onRowSelect}" />
<f:facet name="header">
<p:outputPanel layout="inline" styleClass="tabSpacer">
<h:outputText value="Global Filter:" />
<p:inputText id="globalFilter" onkeyup="PF('dtlTBL').filter()" style="width:150px;margin-left:10px;"/>
</p:outputPanel>
</f:facet>
<p:column width="10">
<f:facet name="header">
<h:outputText value="Sr." />
</f:facet>
<h:outputText value="#{rowIndex+1}" />
</p:column>
<p:columns value="#{liveRangeService.tableHeaderNames}"
var="mycolHeader"
width="#{colIndex==0?'10%':colIndex==1?'70%':colIndex==2?'10%':colIndex==3?'10%':'0'}"
columnIndexVar="colIndex" selectRow="true"
sortBy="#{result[mycolHeader.value]}"
filterBy="#{result[mycolHeader.value]}"
filterMatchMode="contains"
>
<f:facet name="header">
<h:outputText value="#{mycolHeader.value}" />
</f:facet>
<h:outputText value="#{result[mycolHeader.key].value}" />
<br />
</p:columns>
</p:dataTable>
</p:dialog>
Пожалуйста, сообщите изменение в коде.