当我尝试加载页面时,数据表为空。使用<h:dataTable ... />
数据显示在行中。然而,经过进一步检查后,列表实际上已经写好....但似乎它直接在数据表的value属性中使用列表的toString()。有什么问题?
支持bean
@Named
@RequestScoped
public class QuestionTableBacking {
@Inject
private QuestionServiceLocal questionService;
public List<Question> getAllQuestions() {
return questionService.getAllQuestions();
}
}
Facelet文件
<h:form>
<p:dataTable value="#{questionTableBacking.allQuestions}" var="question" >
<p:column>
<h:outputText value="#{question.description}" />
</p:column>
<p:column>
<h:link outcome="report" value="Rapporter" />
</p:column>
</p:dataTable>
</h:form>
这就是我在firebug中看到的
<p:datatable value="[com.mycompany.myapp.domain.Question@7cf9175c, com.mycompany.myapp.domain.Question@456cd91d, com.mycompany.myapp.domain.Question@6d222286,..... var="question">
<p:column>
</p:column>
<p:column><a href="/myapp/report.faces">Report</a>
</p:column>
</p:datatable>
POM文件(它们包含在正确的父元素中)
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.2</version>
<scope>compile</scope>
</dependency>
<repository>
<id>prime-repo</id>
<name>PrimeFaces Maven Repository</name>
<url>http://repository.primefaces.org</url>
<layout>default</layout>
</repository>
警告:此页面调用XML命名空间http://primefaces.org/ui 使用前缀p声明但该命名空间不存在taglibrary。
完整档案:
<?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:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:o="http://openfaces.org/">
<h:head>
<title>Simple JSF Facelets page</title>
</h:head>
<h:body>
<ui:composition template="templates/masterLayout.xhtml">
<ui:define name="windowTitle">Question</ui:define>
<ui:define name="content">
<div id="page-intro">
<h2>Titile</h2>
<p>Blah blah</p>
</div>
<h:form>
<div class="question-filter-container">
<o:inputTextFilter id="quesiton-filter" styleClass="input-text question-filter" for="question-table"
expression="#{question.description}"
promptText="" />
</div>
<o:dataTable value="#{questionTableBacking.allQuestions}" var="question" rowKey="#{question.id}"
id="question-table" pageSize="25" applyDefaultStyle="false"
cellspacing="0">
<f:facet name="below">
<o:dataTablePaginator id="paginator" pageNumberPrefix="Side" pageCountPreposition="av"
styleClass="question-paginator" />
</f:facet>
<o:column>
<h:outputText value="#{question.description}" />
</o:column>
<o:column bodyClass="question-operations">
<h:link outcome="report" value="Report" />
</o:column>
</o:dataTable>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
答案 0 :(得分:0)
#{question.description}
应该转换为当前迭代的String
对象question
内的.description
值,这不是您在输出中看到的内容吗?如果那样的话,那就好了...
修改强>
在查看您的问题更新后,您似乎没有在项目中添加primefaces jar ...
您是否已将xmlns:p =“http://primefaces.org/ui”添加到您的xhtml文件中?