在以下页面中,我无法加载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));
}
加载的部分index.xhtml页面f:metadata
<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 中具有相同的确切代码时,它就不起作用了。