java - 构建具有不同列数的 html 表

标签 java jsf icefaces

我正在使用 Java 和 icefaces,我需要构建一个每次都有不同列数的表。

到目前为止,我找到的最好的例子是 the icefaces website

我试图让列数是动态的,但我不知道如何获取 html 页面中的单元格值。 这是我的代码:

我的 bean :

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 中的数据 --> 获取索引 [col.value] 中 obj 中的值。

最佳答案

您可以尝试使用 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>

关于java - 构建具有不同列数的 html 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15403882/

相关文章:

java - Android Studio 从 jar 中排除类或文件

java - 在匿名类中调用 super 方法

java - 使用 ui :param and access them in Backing bean 传递值

jsf - JSF 组件 id 中生成的前缀 j_idt33 是什么?

jsf - Primefaces SelectOneButton : Change individual button styles

JSF 2.0 + Icefaces 2.0.0 Beta2 和 Tomcat 7 失败

Java xml 编写器覆盖

java - 有没有一个软件可以实时查看JVM堆内存中对象的变化?

jsf - 阶段监听器仅在没有回发时才监听

java - JSF 和 applicationscoped bean 连接(发布/订阅)