【发布时间】:2015-04-28 19:38:08
【问题描述】:
我有这个 cdBean.java 和一个名为 ViewAllCd 的方法来显示数据库中的所有 Cd。但是,当它在 xhtml 上调用时,输出不存在.. 我如何获得输出?
这是我的 cdBean:
package Bean;
import Entities.Compactdiscs;
import javax.ejb.Stateless;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
import java.util.List;
import javax.inject.Named;
/**
*
* @author User
*/
@Named
@Stateless
public class cdBean implements cdBeanLocal {
@PersistenceUnit EntityManagerFactory emf;
/**
*
* @return
*/
@Override
public List<Compactdiscs> ViewAllCd(){
return emf.createEntityManager().createNamedQuery("Compactdiscs.findAll",Compactdiscs.class).getResultList();
}
// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method")
}
这是我的 xhtml 文件:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
>
<head>
<title>allcd</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<h1>All Cd</h1>
<h:dataTable value="#{cdBean.ViewAllCd}" var="c" border="1">
<h:column>
<f:facet name="header">
<h:outputText value="ID" />
</f:facet>
<h:outputText value="#{c.cdID}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:outputText value="#{c.cdName}" />
</h:column>
</h:dataTable>
</body>
</html>
【问题讨论】:
-
请在您的 xhtml 上使用
h:head代替head,并使用h:body代替body。 -
您正在尝试将应用程序层与域模型和/或业务层合并在一起。请考虑隔离它们。