例如,我有一个像这样的csv文件:
column1,column2,column3,column4
1,one,un,eins
2,two,deux,zwei
3,three,trois,drei
4,four,quattre,four
5,five,cinque,fuenf
6,six,six,sechs
7,seven,sept,sieben
8,eight,huit,acht
9,nine,neuf,neun
10,ten,dix,zehn
但是由于我有多个csv文件,列数会发生变化。所以我使用了这个dynamic columns并且我已经成功显示了一些随机csv文件的列标题,但是我无法将列的数据显示到primefaces数据表中。我如何显示文件的内容?
.xhtml:
<p:dataTable var="attr" value="#{newClass.a_name2}" scrollable="true" scrollWidth="50%" scrollHeight="150">
<p:columns width="125" value="#{newClass.columns}" var="column" >
<f:facet name="header">
<h:outputText value="#{column.header}" />
</f:facet>
<h:outputText value="#{attr[column.property]}" />
</p:columns>
</p:dataTable>
bean:
@ManagedBean
@ViewScoped
public class NewClass implements Serializable{
private List<Attribute> a_name2;
private List<ColumnModel> columns;
private String columnTemplate;
public void settingValue {
//csv file
columnTemplate=;//setting column names.
a_name2=createFile(numberofRowsinCsvFile);
createDynamicColumns();
}
private void createDynamicColumns() {
String[] columnKeys = getColumnTemplate().split("\t");
columns = new ArrayList<ColumnModel>();
for(String columnKey : columnKeys) {
columns.add(new ColumnModel(columnKey.toUpperCase(),columnKey));
}
}
public String getColumnTemplate() {
return columnTemplate;
}
public void setColumnTemplate(String columnTemplate) {
this.columnTemplate = columnTemplate;
}
public List<ColumnModel> getColumns() {
return columns;
}
public void setColumns(List<ColumnModel> columns) {
this.columns = columns;
}
public List<Attribute> getA_name2() {
return a_name2;
}
public void setA_name2(List<Attribute> a_name2) {
this.a_name2 = a_name2;
}
public List createFile(int size) {
List list = new ArrayList();
for(int i = 0 ; i < size ; i++) {
list.add(i);
}
return list;
}
static public class ColumnModel implements Serializable {
private String header;
private String property;
public ColumnModel(String header, String property) {
this.header = header;
this.property = property;
}
public String getHeader() {
return header;
}
public String getProperty() {
return property;
}
}
}
我收到错误:
javax.el.PropertyNotFoundException: /index.xhtml @53,70 value="#{attr[column.property]}": The class 'java.lang.Integer' does not have the property 'outlook'.