每行数据表7个项目

时间:2014-07-21 06:34:28

标签: jsf datatable

我们说我有一个月内所有日子的清单,我想把它打印成日历。我希望每一行都有一周,然后是一个分行

在我下面的例子中,我会在每一行上获得一天,如下所示: enter image description here

在JSF中每行获得7天的最佳方法是什么? enter image description here

示例代码:

查看:

 <h:dataTable value="#{myController.dayList}" var="day">
            <h:column>
                <h:outputText value="#{day}"/>
            </h:column>

 </h:dataTable>

Backbean:

@ManagedBean(name = "myController")
@SessionScoped
public class MyController {

  private List <int> dayList;

  public MyController()
  {
      dayList = getAllDaysInMonth();
  }

  public List <int> getAllDaysInMonth()
  {
   .....
  }

  public List <int> getDayList()
  {
      return dayList;
  }

  public void setDayList(List <int> dayList)
  {
    this.dayList = dayList;
  }

}

1 个答案:

答案 0 :(得分:1)

如果您想在项目中使用Primefaces,可以这样做。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">
<body>
    <p:dataGrid value="#{myController.dayList}" var="day" columns="7">
        <p:panel style="text-align: center; background-color: skyblue; width: 100px; height: 100px;">
            Day ${day}
        </p:panel>
    </p:dataGrid>
</body>
</html>

Controller类

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

@Named(value = "myController")
@SessionScoped
public class MyController implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    List<Integer> dayList = new ArrayList<>();

    public MyController() {
    }

    @PostConstruct
    public void init() {
        for(int i = 1; i <= 31; i++) {
            dayList.add(new Integer(i));
        }
    }

    public List<Integer> getDayList() {
        return dayList;
    }

    public void setDayList(List<Integer> dayList) {
        this.dayList = dayList;
    }
}

enter image description here

看起来不是很好,但做你需要的。

帕特里克