JSF DataTable值来自方法

时间:2017-07-15 06:47:29

标签: jsf datatable

我可以从JSF中获取DataTable的值,该方法将返回一个对象列表而不是从属性的getter获取吗?
FilmBean.java

@ManagedBean(name = "filmBean")
@SessionScoped
public class FilmBean
{
    private List<Film> filmList;
    private final Helper helper;
    public FilmBean()
    {
        helper = new Helper();
    }

    @PostConstruct
    public void init()
    {
        filmList = helper.getFilmTitles(0, 100);
    }

    public List getFilmTitles()
    {
        return helper.getFilmTitles(0, 100);
    }

    public List getFilmList()
    {
        return filmList;
    }
}

jsf.xhtml

<h:body>
<h:dataTable value = "#{filmBean.filmList}" var = "film">
        <h:column>
            <f:facet name = "header">Film Title</f:facet>                   
                #{film.title}
        </h:column>

        <h:column>
            <f:facet name = "header">Release Year</f:facet>
                #{film.releaseYear}
        </h:column>
    </h:dataTable>
</h:body>

上述代码完美无缺,直到我将value = "#{filmBean.filmList}"更改为value = "#{filmBean.getFilmTitles()}"我才会收到错误:

org.hibernate.TransactionException: nested transactions not supported

但他们都回到了名单上,为什么会这样呢?看起来好几次调用这个方法。

0 个答案:

没有答案