Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在数据表中显示查询(选择计数分组依据)_Java_Jsf_Datatable_Richfaces - Fatal编程技术网

Java 在数据表中显示查询(选择计数分组依据)

Java 在数据表中显示查询(选择计数分组依据),java,jsf,datatable,richfaces,Java,Jsf,Datatable,Richfaces,这个查询在控制台上运行良好,但现在我想在dataTable的xhtml页面中显示它,我尝试了这个尝试,但没有成功 List<Object[]> results; public List<Object[]> getResults() { results = entityManager.createQuery("select d.lib_naturepanne,count(r) as nbrr"+" from NaturePanne d JOIN d.listReparat

这个查询在控制台上运行良好,但现在我想在dataTable的xhtml页面中显示它,我尝试了这个尝试,但没有成功

List<Object[]> results; 
public List<Object[]> getResults() {
results = entityManager.createQuery("select d.lib_naturepanne,count(r) as nbrr"+" from NaturePanne d JOIN d.listReparation r  GROUP BY d.lib_naturepanne").getResultList();

for (Object[] result : results) {
String name = (String) result[0];
int count = ((Number) result[1]).intValue();
System.out.println("name "+name+ " count "+count);

    }
return results; 
file.xhtml

<rich:dataTable id="tablereparation"  value="#{stat.results}" var="rep">
<h:column headerClass="headerleftfacet">
<f:facet name="header">Name</f:facet>
<h:outputText value="#{rep.results.name}" /></h:column>

 <h:column headerClass="headermiddlefacet">
 <f:facet name="header">Count</f:facet>
  <h:outputText value="#{rep.results.count}" /></h:column>
 </rich:dataTable>          
{rep.results.name}错误。您有一个列表,因此您要么得到如下结果:{rep[0]},要么将对象[]映射到某种POJO

public class NameCount {
    String name;
    int count;
    public NameCount(Object[] o) {
        name = (String) o[0];
        count = (Integer) o[1];
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getCount() {
        return count;
    }
    public void setCount(int count) {
        this.count = count;
    }
}

 public List<NameCount> getResults() {
    List<Object[]> results = entityManager.createQuery(...);

    List<NameCount> rowset = new ArrayList<NameCount>();
    for (Object[] o : results) {
        rowset.add(new NameCount(o));
    }
    return rowset;
 }

您得到了什么错误?还要添加managedbean impl谢谢,我只想在没有POJO的情况下进行测试