1

我有一个带有 el 表达式的简单 xhtml 页面。但是这个表达式不会得到解决,也不会抛出任何错误。

测试.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!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:p="http://primefaces.org/ui"
      xml:lang="en" lang="en">
<h:head>
    <title></title>
</h:head>
<h:body>
    test
#{ffs.count}
</h:body>
</html>

豆豆

@Named("ffs")
public class Test implements Serializable {

    @PersistenceContext(type = PersistenceContextType.TRANSACTION)
    EntityManager em;


    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public int getCount() {
        Game game = new Game();
        game.setName("Test");
        game.setType(Game.Type.PC);

        em.persist(game);
        em.flush();



        System.out.println(em.createQuery("Select g from Game g").getResultList().size());

        return em.createQuery("Select g from Game g").getResultList().size();

    }
}

呈现的 HTML 输出

<?xml version="1.0" encoding="UTF-8"?>
<!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" xml:lang="en" lang="en"><head><link type="text/css" rel="stylesheet" href="/Games/faces/javax.faces.resource/theme.css?ln=primefaces-aristo" />
    <title></title></head><body>
    test

</body>
</html>
4

0 回答 0