0

当我尝试加载页面时,数据表为空。使用<h:dataTable ... />数据显示在行中。然而,经过进一步检查,列表实际上是写的......但它似乎直接在数据表的 value 属性中使用了列表的 toString() 。怎么了?

支持豆

@Named
@RequestScoped
public class QuestionTableBacking {

    @Inject
    private QuestionServiceLocal questionService;

    public List<Question> getAllQuestions() {
        return questionService.getAllQuestions();
    }
}

小面文件

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

这是我在萤火虫中看到的

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

警告:此页面调用以前缀 p 声明的 XML 命名空间http://primefaces.org/ui ,但该命名空间不存在标记库。

完整文件:

<?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>
4

1 回答 1

0

#{question.description}应该变成String当前迭代question对象.description属性中的值,这不是您在输出中看到的吗?如果是这样的话,那一切都好……

编辑

在查看您的问题更新后,您似乎还没有将 primefaces jar 添加到您的项目中......

您是否已将 xmlns:p="http://primefaces.org/ui 添加到您的 xhtml 文件中?

于 2012-04-22T11:29:03.733 回答