我正在使用Java和icefaces,我需要构建一个每次都有不同列数的表。
到目前为止,我找到的最好的例子是the icefaces website
我试图让列数变为动态,但我不知道如何在html页面中获取单元格值。 这是我的代码:
我的豆子:
public class DynamicColumnsBean implements Serializable {
int randomRows ;
int randomCol ;
List<Task> data; // rows data
List<ColumnModel> columns ;
public DynamicColumnsBean() {
super();
Random rn = new Random();
randomRows = rn.nextInt() % 40;
randomCol = rn.nextInt() % 30;
if(randomRows==0) randomRows=10;
if(randomCol==0) randomCol=7;
if(randomRows<0) randomRows*=-1;
if(randomCol<0) randomCol*=-1;
columns = new ArrayList<ColumnModel>();
for (int i=0 ; i< randomCol ; i++ )
{
columns.add(new ColumnModel(i, "ID "+ i +" "));
}
data = new ArrayList<Task>() ; //row objects
for (int i=0 ; i< randomRows ; i++ )
{
List<String> obj = new ArrayList<String>() ;
for (int j=0 ; j< randomCol ; j++ )
{
obj.add("row "+i +" col "+j);
}
Task temp = new Task(obj);
data.add(temp);
}
}
public List<Task> getData()
{ return data; }
public void setData(ArrayList<Task> data)
{ this.data = data; }
public List<ColumnModel> getColumns() {
return columns; }
public void setColumns(ArrayList<ColumnModel> columns) {
this.columns = columns; }
}
public class Task {
List<String> obj ;
public Task() {
super();
}
public Task(List<String> obj) {
super();
obj = new ArrayList<String>();
this.obj = obj;
}
public List<String> getObj() {
return obj; }
public void setObj(List<String> obj) {
this.obj = obj; }
}
public class ColumnModel {
int value; // represents sortBy / filterBy as one field
String headerText;
public ColumnModel(int i, String headerText) {
this.value = i;
this.headerText = headerText;
}
public int getValue() {
return value; }
public void setValue(int value) {
this.value = value; }
public String getHeaderText() {
return headerText; }
public void setHeaderText(String headerText) {
this.headerText = headerText; }
}
<ace:dataTable value="#{dynBean2.data}" var="row" scrollable="true"
height="200" paginator="true" rows="5" >
<c:forEach items="#{dynBean2.columns}" var="col">
<ace:column headerText="#{col.headerText}" style="width: 40px" >
<ice:outputText value=" #{row['obj'[col.value]]}"></ice:outputText>
</ace:column>
</c:forEach>
</ace:dataTable>
我的问题是:
ice:outputText value=" #{row['obj'[col.value]]}"
我需要的值是:获取索引i中的数据 - &gt;在index [col.value]中获取它的obj值。
答案 0 :(得分:0)
您可以尝试使用varStatus:
<c:forEach items="#{dynBean2.columns}" var="col" varStatus="colStatus">
<ace:column headerText="#{col.headerText}" style="width: 40px" >
<ice:outputText value=" #{row.obj[colStatus.index]}"></ice:outputText>
</ace:column>
</c:forEach>