【发布时间】:2018-03-11 18:05:55
【问题描述】:
在以下页面中,我无法加载automobileLists,因为填充它的方法位于f:metadata 中的组件之外。我有一个 nullPointerException 错误。
部分代码:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>title</title>
</h:head>
<f:metadata>
<f:viewAction action="#{primeAutomobileController.populateAutomobileFieldList}"/>
</f:metadata>
<ui:composition template="layout/template.xhtml">
<ui:define name="content">.....................
我加载它的唯一方法是将primeAutomobileController 限定为会话而不是原始请求,并通过按钮从前一页调用该方法,我希望它在页面开头加载而不是以前调用它。有问题的方法:
public void populateAutomobileFieldList(){
List<String> automobileFieldSource = new ArrayList<>();
List<String> automobileFieldTarget = new ArrayList<>();
automobileFieldSource.add("Make");
automobileFieldSource.add("Model");
automobileFieldSource.add("Year");
automobileFieldSource.add("Description");
setAutomobileList(new DualListModel<>
(automobileFieldSource, automobileFieldTarget));
}
加载f:metadata 的部分index.xhtml页面
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>title</title>
</h:head>
<f:metadata>
<f:viewAction action="#{primeAutomobileController.loadAutomobiles}"/>
<f:viewAction action="#{primeAutomobileController.populateAutomobileFieldList}"/>
</f:metadata>
<ui:composition template="layout/template.xhtml">
<ui:define name="content"> ......................
f:metadata 中的两种方法都可以正确加载,就像我正在关注的视频教程中的示例所示,但是当它在不同的 xhtml 中使用相同的完全相同的代码时,它就不起作用了。
【问题讨论】:
标签: jsf metadata facelets templating viewaction