java - 使用 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”时出错
而且只是一个空白屏幕。感谢您提供任何帮助,因为我已经尽了最大的努力进行研究,并且不知道如何继续。
解决方案
通过将 Bean 中的 getter 重命名为 jsp 数据表中的 value 参数中调用的内容,此问题已得到解决。
Bean -> getExampleList() jsp -> value="#{bean.ExampleList}"
仅当我想保持 ArrayList 私有时,因为我收到的错误是因为变量是私有的并且 gettter 与我调用的不匹配。
推荐阅读
- javascript - JS输出选项选择值作为链接中的get参数
- jsf - p:galleria 在底部没有褪色,就像 PrimeFaces 展示页面上的情况一样
- bash - 运行 .command bash 脚本时出现“未指定的异常”
- asp.net - 使用 .NET Core 对象持久性模型查询 DynamoDB GSI 组合键时出现问题
- java - “在 SpringMVC 中找不到类型的返回值的转换器:类 java.lang.Integer”
- python - 为什么只有在使用 input() 方法时才会收到 TypeError?
- python - 如何从默认的 Django 模型重命名模型字段?
- javascript - 使用函数检查项目是否在数组中,然后从数组中删除该项目
- ios - 在 iOS 13 测试版中,应用程序在应用程序启动时崩溃
- git - 从 Github 中删除一个特定的提交