0

Can I get value of DataTable in JSF from method that will return a list of objects instead of getting from getter of an attribute?
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>

The code above works perfectly until I change value = "#{filmBean.filmList}" to value = "#{filmBean.getFilmTitles()}" I will get error:

org.hibernate.TransactionException: nested transactions not supported

But they are both return the list, why is this happen? It looks like it calls the method several time.

Newbie
  • 1,584
  • 9
  • 33
  • 72
  • `org.hibernate.TransactionException: nested transactions not supported` is not a problem of web layer (JSF or otherwise). It is related to transaction demarcation on the persistence layer. It is likely that you are trying to begin a database transaction without fully completing the previous transaction already running. This goes to a further abstract layer, Hibernate / JPA. – Tiny Jul 15 '17 at 07:07
  • @Tiny this is why I say `getFilmTitles()` method has been called several time. And why is this happend? – Newbie Jul 15 '17 at 07:57
  • Getters should **never** do real work!. And an additional suggestion: read all Q/A with at least 30 upvotes https://stackoverflow.com/questions/tagged/jsf?sort=votes. Lots of basic knowledge to gain or at least know Q/A exists in a certain direction. And also take a look at https://jsf.zeef.com – Kukeltje Jul 15 '17 at 08:02

0 Answers0