从JSF页面找不到CDI Bean

时间:2013-07-19 18:19:54

标签: java jsf jboss cdi

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

test.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>

Cdi Bean

@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>

0 个答案:

没有答案