我有这个名为ViewAllCd的方法的cdBean.java来显示数据库中的所有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>
答案 0 :(得分:0)
尝试添加此方法。 Richfaces期望getter和setter跟随(我不记得确切名称)java命名约定
public List<Compactdiscs> getViewAllCd(){
return your_data_here;
}
或者你可以这样做来调用你的方法:
<h:dataTable value="#{cdBean.ViewAllCd()}" var="c" border="1">