首页 > 解决方案 > 使用 JPA 和 Eclipselink 在 JSP 文件中显示现有数据库表中的数据

问题描述

不确定我是否在某个地方错过了这个过程中的一个步骤,或者它是否只是语法,因为我是这个结构的新手。我现在只想回到我的 bean,但如果需要,我可以建立我的逻辑类、模型类和其他任何东西。这是我的 JSP 的样子:

        <h:dataTable 
            id="viewExampleTable" 
            value="#{ExampleBean.exampleList}"
            binding="#{ExampleBean.exampleTable}"
            var="example"
            styleClass="dataTable" border="1"
            style="width: 500px; word-wrap: break-word;"
            columnClasses="colWidth80,colWidth80,colWidth80,colWidth80">
            <h:column>
                <h:outputText value="example.Id"></h:outputText>
            </h:column>
            <h:column>
                <h:outputText value="example.importDate"></h:outputText>
            </h:column>
            <h:column>
                <h:outputText value="example.serviceId"></h:outputText>
            </h:column>
            <h:column>
                <h:outputText value="example.rowTimestamp"></h:outputText>
            </h:column>
        </h:dataTable>

这是豆:

private HtmlDataTable exampleTable;
private ArrayList exampleList = new ArrayList();

public HtmlDataTable getExampleTable(){
   return this.exampleTable;
}

public void setExampleTable(HtmlDataTable dataTable){
   this.exampleTable = dataTable;
}

public ArrayList<Example> getExample(){
   ArrayList<Example> list = ExampleLogic.getExampleRecords();
   this.exampleList = list;
   return this.exampleList
}

public void setExample(ArrayList<Example> list){
   this.exampleList = list;
}

我遇到的这个问题是,每当将其部署到服务器时,我都会收到此错误:

javax.faces.el.PropertyNotFoundException:从 examplePath.view.ExampleBean 类型的 bean 获取属性“exampleList”时出错

而且只是一个空白屏幕。感谢您提供任何帮助,因为我已经尽了最大的努力进行研究,并且不知道如何继续。

标签: javajspjpaeclipselinkpersistence

解决方案


通过将 Bean 中的 getter 重命名为 jsp 数据表中的 value 参数中调用的内容,此问题已得到解决。

Bean -> getExampleList() jsp -> value="#{bean.ExampleList}"

仅当我想保持 ArrayList 私有时,因为我收到的错误是因为变量是私有的并且 gettter 与我调用的不匹配。


推荐阅读